View Issue Details

IDProjectCategoryView StatusLast Update
0002186XdebugStep Debuggingpublic2023-07-14 09:14
Reporterrstark Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
PlatformLinuxOSRHELOS Version8
Product Version3.2.1 
Target Version3.2devFixed in Version3.2.2 
Summary0002186: Segfault with trampoline functions and debugger activation
Description

Segfault occurs with nested __call invocation with xdebug3 and PHP 8.1.21 (also tested under PHP 8.1.19 and 8.1.11)

Steps To Reproduce

Run the following program

<?php
$anon = new class() {
    function execute() {
        new ReflectionClass(null);
    }
};

(new Wrapper($anon))->execute(
    (new Wrapper($anon))->execute());

class Wrapper
{
    protected $wrapped;
    function __construct($wrapped)
    {
        $this->wrapped = $wrapped;
    }
    public function __call($method, $arguments)
    {
        return call_user_func([$this->wrapped, $method]);
    }
}
Additional Information

The segfault occurs whether or not the class is anonymous. The segfault does not occur with USE_ZEND_ALLOC=0.

The attached backtrace and valgrind / gdb traces are from an xdebug3 build of master at commit cb6882fd47c7591c7f4fb22567a7f2860919d086

It appears the code in debugger.c:121 is attempting to use memory (op_array) that has been freed (see attached gdb-free-trace.out)

Thanks to my collegue Robert for creating the above test script from a more complex scenario.

TagsNo tags attached.
Operating System
PHP Version8.1.10-8.1.19

Relationships

related to 0002175 closedderick Crash with EXC_BAD_ACCESS in xdebug_str_create 

Activities

derick

2023-07-11 16:52

administrator   ~0006591

Your script fails with:

Fatal error: Uncaught Error: Call to undefined method Wrapper::execute() in /home/derick/dev/php/derickr-xdebug/tests/develop/bug02186.phpt on line 8

Error: Call to undefined method Wrapper::execute() in /home/derick/dev/php/derickr-xdebug/tests/develop/bug02186.phpt on line 8

Can you attach the script, please?

cheers,
Derick

derick

2023-07-11 18:00

administrator   ~0006592

Never mind, I saw what was wrong. I can reproduce it and I have a fix, but still need to write a proper test.

derick

2023-07-13 12:59

administrator   ~0006593

https://github.com/xdebug/xdebug/pull/895

derick

2023-07-14 09:04

administrator   ~0006603

https://github.com/xdebug/xdebug/pull/895