Skip to content

Segmentation fault in ext/spl/spl_directory.c #16477

Closed

Description

@YuanchengJiang

Description

The following code:

<?php
$obj = new SplFileObject(__FILE__);
function test($function) {
try {
@$function();
} catch (Throwable) {
}
}
foreach (get_declared_classes() as $class) {
foreach (get_class_methods($class) as $method) {
test([$obj, $method]);
}
}

Resulted in this output:

/php-src/ext/spl/spl_directory.c:650:3: runtime error: member access within null pointer of type 'zend_string' (aka 'struct _zend_string')

PHP Version

nightly

Operating System

ubuntu 22.04

Activity

  1. Girgias commented on Oct 17, 2024

    @Girgias
    Member

    Smaller reproducible:

    $obj = new SplFileObject(__FILE__);
    
    $class = 'SensitiveParameterValue';
    
    foreach (get_class_methods($class) as $method) {
        echo "Method: $method\n";
        try {
            $obj->$method();
        } catch (Throwable $e) {
            echo $e::class, ': ', $e->getMessage(), PHP_EOL;
        }
    }

    The issue seems to possibly be with get_class_methods() as if I set $method = '__debugInfo' explicitly it, it works.

  2. Girgias commented on Oct 17, 2024

    @Girgias
    Member

    Okay I figured out the issue:

    $obj = new SplFileObject(__FILE__);
    
    try {
        $obj->__construct();
    } catch (Throwable $e) {
        echo $e::class, ': ', $e->getMessage(), PHP_EOL;
    }
    $obj->__debugInfo();

    The constructor when it fails sets intern->u.file.open_mode = NULL; which causes the null deref afterwards.

  3. self-assigned this
    on Oct 17, 2024
  4. added 5 commits that reference this issue on Oct 25, 2024
    6a6c3ef
    9f5b5e3
    d353a89
    a19029f
    eab17ae
  5. added 3 commits that reference this issue on Oct 25, 2024
    5d993e9
    7854248
    bfca4c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions