# call_user_func segfault

- Thread: https://externals.io/message/42448
- Original archive: https://news-web.php.net/php.internals/42448
- Started by Derick Rethans on 2009-01-02T15:55:41+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #42448 — Derick Rethans — 2009-01-02T15:55:41+00:00

URL: https://externals.io/message/42448#42448

Hello,

I've been running into a strange segfault with PHP 5.2.x (it works in 
PHP 5.3) when using `call_user_func()` recursively. I can not find out 
what causes it, but I did manage to have a simple test case. For the 
test to crash, you either need a debug build of PHP, or valgrind + 
USE_ZEND_ALLOC=0. You need run the script from within the "test" 
directory as it assumes file system layout. 

There is luckily a simple work around for the bug, by replacing:

call_user_func( $callback, $callbackContext, $sourceDir, $entry, 42 );
with
call_user_func_array( $callback, array( $callbackContext, $sourceDir, $entry, 42 ) );

I uploaded the test case as a .tar archive to 
http://files.derickrethans.nl/test.tar.gz

It'd be ace if you could have a look at it (before I file a bug report).

regards,
Derick

-- 
HEAD before 5_3!: http://tinyurl.com/6d2esb
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org

---

## #42454 — johannes@schlueters.de — 2009-01-02T22:23:18+00:00

URL: https://externals.io/message/42448#42454 · In reply to: #42448

> Hello,
> 
> I've been running into a strange segfault with PHP 5.2.x (it works in 
> PHP 5.3) when using `call_user_func()` recursively. I can not find out 
> what causes it, but I did manage to have a simple test case. For the 
> test to crash, you either need a debug build of PHP, or valgrind + 
> USE_ZEND_ALLOC=0. You need run the script from within the "test" 
> directory as it assumes file system layout. 

I didn't test it as I have no 5.2 right now at hand on this box but I
think call_user_func messes with references in parameters to the called
function. In 5.3 this is fixed by zend_parse_parameters. I saw some code
(Serendipity's way of using Smarty) break with 5.3 since reference
handling changed there, didn't investigate but 5.3 seemed to be correct
on first sight.

Not sure if that's enough of an pointer to help debugging that issue...

johannes

---

## #42607 — Derick Rethans — 2009-01-13T15:54:14+00:00

URL: https://externals.io/message/42448#42607

> Stanislav Malyshev wrote:
>
> > […]
> 
> The crash is definitely caused by argument stack reallocation.
> 
> PHP-5.3 has a segmented stack which solves the issue.
> 
> I don't think we should try to solve it in 5.2 as it may be a
> significant BC break for PHP debuggers.

I'd rather have PHP not crash, than having to do a little work on making 
a debugger work again. 

regards,
Derick

-- 
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org
twitter: derickrethans
