php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46241 Error handler stacking broken
Submitted: 2008-10-06 13:03 UTC Modified: 2008-11-19 08:26 UTC
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:6 of 6 (100.0%)
Same Version:5 (83.3%)
Same OS:1 (16.7%)
From: toby@php.net Assigned: colder (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3CVS-2008-11-11 OS: *
Private report: No CVE-ID: None
 [2008-10-06 13:03 UTC] toby@php.net
Description:
------------
Stacking 2 error handlers is broken. With object methods only the first error handler is invoked, with functions I even get a PHP crash.

Reproduce code:
---------------
-------------------------- Object methods -----------------------

<?php

class ErrorHandling
{

    public function errorHandler1( $errno, $errstr )
    {
        echo "Caught on first level: '$errstr'\n";
        return true;
    }

    public function errorHandler2( $errno, $errstr )
    {
        echo "Caught on second level: '$errstr'\n";
        return true;
    }
}

$err = new ErrorHandling();

set_error_handler( array( $err, 'errorHandler1' ) );
set_error_handler( array( $err, 'errorHandler2' ) );

trigger_error( 'Foo', E_USER_WARNING );

?>

-------------------------- Functions -----------------------

<?php

function errorHandler1( $errno, $errstr )
{
    echo "Caught on first level: '$errstr'\n";
    return true;
}

function errorHandler2( $errno, $errstr )
{   
    echo "Caught on second level: '$errstr'\n";
    return true;
}

set_error_handler( 'errorHandler1' );
set_error_handler( 'errorHandler2' );

trigger_error( 'Foo', E_USER_WARNING );

?>

Expected result:
----------------
-------------------------- Object methods ----------------------- Caught on second level: 'Foo'
-------------------------- Functions -----------------------
Caught on second level: 'Foo'

Actual result:
--------------
-------------------------- Object methods ----------------------- 
Caught on first level: 'Foo'
-------------------------- Functions -----------------------
Caught on first level: 'Foo'
zend_mm_heap corrupted

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-21 21:04 UTC] clemens dot kalb at netlogix dot de
Here is one thing that has been more clear in the other, duplicate and now closed - bug entry (#46338). The first code sample with object methods does not only miss out on the second error handler, it also segfaults *on shutdown* of the PHP process:

-------------------SNIP---------------------
Starting program: /usr/bin/php5 segfault2.php
[Thread debugging using libthread_db enabled]
[New Thread -1215695168 (LWP 5622)]
Caught on first level: 'Foo'

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1215695168 (LWP 5622)]
zend_hash_destroy (ht=0xb786bf08) at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/Zend/zend_hash.c:524
524                     p = p->pListNext;
(gdb) bt
#0  zend_hash_destroy (ht=0xb786bf08) at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/Zend/zend_hash.c:524
#1  0x0836dc41 in _zval_dtor_func (zvalue=0xb786bf70) at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/Zend/zend_variables.c:43
#2  0x0836d3b3 in zend_ptr_stack_apply (stack=0x880d470, func=0x836dbf0 <_zval_dtor_func>) at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/Zend/zend_ptr_stack.c:90
#3  0x0836d3fd in zend_ptr_stack_clean (stack=0x880d470, func=0x836dbf0 <_zval_dtor_func>, free_elements=1 '\001')
    at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/Zend/zend_ptr_stack.c:97
#4  0x08360f68 in shutdown_executor () at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/Zend/zend_execute_API.c:272
#5  0x0836e28b in zend_deactivate () at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/Zend/zend.c:899
#6  0x08316df6 in php_request_shutdown (dummy=0x0) at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/main/main.c:1522
#7  0x08408203 in main (argc=2, argv=0xbffa0b14) at /usr/src/dailybuild/builds/20081021/php5-5.3.0-200810211830/sapi/cli/php_cli.c:1311
-------------------SNAP---------------------

The problem persists with PHP 5.3.0alpha3-dev (cli) (built: Oct 21 2008 22:10:26).
 [2008-10-22 22:32 UTC] ezyang@php.net
Upgrading to critical, as it is a crash and clear breakage of functionality.
 [2008-10-28 22:45 UTC] typo3 at maltejansen dot de
Just a notice.
This bug has the same origin as http://bugs.php.net/bug.php?id=46220
 [2008-11-11 10:33 UTC] jani@php.net
Still happens using latest CVS checkout of PHP_5_3. (works fine still with PHP_5_2 :)
 [2008-11-19 08:26 UTC] colder@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC