php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34062 Crash in catch block when many arguments are used
Submitted: 2005-08-10 08:52 UTC Modified: 2005-08-10 16:16 UTC
From: feldgendler at mail dot ru Assigned: dmitry (profile)
Status: Closed Package: Reproducible crash
PHP Version: 6.0.0-dev OS: Debian GNU/Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: feldgendler at mail dot ru
New email:
PHP Version: OS:

 

 [2005-08-10 08:52 UTC] feldgendler at mail dot ru
Description:
------------
PHP crashes in a catch block. It happened in a real program, and I've gradually reduced its complexity until I came to the simple testcase I'm posting below. Both mod_php5 for Apache 2 and php5-cli crash on this testcase.

Here is what I found during research:

In the beginning, I had multiple functions calling each other, like this:

catch (Exception $e) {
    function f2() { f3(0, 0); }
}
function f3() { f4(0, 0, 0); }
function f4() { f5(0, 0); }

...up to a quite deep nesting. I found that I can keep PHP crashing if I carry the zeros from one function call to another, as long as their total number does not decrese. I could even carry the zeros between the catch block and the try block. Also I could exchange one level of nesting for two additional zeros. So I collapsed them all in the argument list of max(). The max() function was chosen arbitararily, any function that takes unlimited number of arguments will do. The zeros can also be replaced with values of any type. The crash can also be reproduced using set_exception_handler() instead of a catch block.

Reproduce code:
---------------
<?

function f1() { throw new Exception; }
function f2() { echo "here\n"; }

try {
      // Currently it's the minimum required number of zeros
      // If you remove one, it won't crash
	max(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, f1());
} catch (Exception $e) {
	echo "(((\n";
	f2(0, 0, 0); // Won't crash if less than 3 zeros here
	echo ")))\n";
}

?>

Expected result:
----------------
(((
here
)))

Actual result:
--------------
(((
here
Segmentation fault

Here is the stack dump (obtained from php-cli):

#0  0x081fb0b6 in _zval_ptr_dtor ()
#1  0x0822b47c in zend_do_fcall_common_helper ()
#2  0x0823bb73 in zend_do_fcall_handler ()
#3  0x08228c39 in execute ()
#4  0x08208414 in zend_execute_scripts ()
#5  0x081ce03d in php_execute_script ()
#6  0x0824c284 in main ()

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-10 10:19 UTC] tony2001@php.net
Dmitry, take a look at it plz, I can reproduce it with the latest CVS.
 [2005-08-10 10:35 UTC] feldgendler at mail dot ru
"Version: 6.0.0-dev"

Is this a misprint?
 [2005-08-10 10:37 UTC] derick@php.net
No, 6.0.0-dev is correct. I still have to change the snapshot's builder though.
 [2005-08-10 10:45 UTC] tony2001@php.net
No. And today is not 1st of April too.
See http://news.php.net/php.internals/17668

 [2005-08-10 15:12 UTC] dmitry@php.net
Fixed in CVS HEAD (6,0), PHP_5_1 and PHP_5_0.
 [2005-08-10 16:16 UTC] feldgendler at mail dot ru
Can I have the patch?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC