cvs: ZendEngine2 / zend.c /tests bug47714.phpt

[email protected] ("Dmitry Stogov") Thu, 26 Mar 2009 10:56:25 -0000
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1238064985@cvsserver>
dmitry		Thu Mar 26 10:56:25 2009 UTC

  Added files:                 
    /ZendEngine2/tests	bug47714.phpt 

  Modified files:              
    /ZendEngine2	zend.c 
  Log:
  Fixed bug #47714 (autoloading classes inside exception_handler leads to crashes)
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend.c?r1=1.430&r2=1.431&diff_format=u
Index: ZendEngine2/zend.c
diff -u ZendEngine2/zend.c:1.430 ZendEngine2/zend.c:1.431
--- ZendEngine2/zend.c:1.430	Wed Mar 18 10:49:35 2009
+++ ZendEngine2/zend.c	Thu Mar 26 10:56:25 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend.c,v 1.430 2009/03/18 10:49:35 dmitry Exp $ */
+/* $Id: zend.c,v 1.431 2009/03/26 10:56:25 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_extensions.h"
@@ -1781,20 +1781,20 @@
 					zval *orig_user_exception_handler;
 					zval **params[1], *retval2, *old_exception;
 					old_exception = EG(exception);
-					zend_exception_save(TSRMLS_C);
+					EG(exception) = NULL;
 					params[0] = &old_exception;
 					orig_user_exception_handler = EG(user_exception_handler);
 					if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
 						if (retval2 != NULL) {
 							zval_ptr_dtor(&retval2);
 						}
-						zend_exception_restore(TSRMLS_C);
 						if (EG(exception)) {
 							zval_ptr_dtor(&EG(exception));
 							EG(exception) = NULL;
  						}
+						zval_ptr_dtor(&old_exception);
 					} else {
-						zend_exception_restore(TSRMLS_C);
+						EG(exception) = old_exception;
 						zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
 					}
 				} else {

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug47714.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug47714.phpt
+++ ZendEngine2/tests/bug47714.phpt
--TEST--
--FILE--
<?php
function au($class) {
        eval('class handler {
                  function handle($e) {
                      echo $e->getMessage()."\n";
                  }
              }');
}

function __autoload($class) {
        au($class);
}

//spl_autoload_register('au');

set_exception_handler(function($exception) {
        $h = new handler();
        $h->handle($exception);
});

throw new Exception('exception');
?>
--EXPECT--
exception