b74969
From 3c87945c95c9c31986e690bb046c70e58c8d8896 Mon Sep 17 00:00:00 2001
b74969
From: Xinchen Hui <laruence@php.net>
b74969
Date: Wed, 5 Jun 2013 17:25:00 +0800
b74969
Subject: [PATCH] Fixed bug #64960 (Segfault in gc_zval_possible_root)
b74969
b74969
---
b74969
 NEWS                     |  2 ++
b74969
 Zend/tests/bug64960.phpt | 40 ++++++++++++++++++++++++++++++++++++++++
b74969
 Zend/zend_execute_API.c  |  6 ++----
b74969
 3 files changed, 44 insertions(+), 4 deletions(-)
b74969
 create mode 100644 Zend/tests/bug64960.phpt
b74969
b74969
diff --git a/Zend/tests/bug64960.phpt b/Zend/tests/bug64960.phpt
b74969
new file mode 100644
b74969
index 0000000..b31cca3
b74969
--- /dev/null
b74969
+++ b/Zend/tests/bug64960.phpt
b74969
@@ -0,0 +1,40 @@
b74969
+--TEST--
b74969
+Bug #64960 (Segfault in gc_zval_possible_root)
b74969
+--FILE--
b74969
+
b74969
+// this makes ob_end_clean raise an error
b74969
+ob_end_flush();
b74969
+
b74969
+class ExceptionHandler {
b74969
+	public function __invoke (Exception $e)
b74969
+	{
b74969
+		// this triggers the custom error handler
b74969
+		ob_end_clean();
b74969
+	}
b74969
+}
b74969
+
b74969
+// this must be a class, closure does not trigger segfault
b74969
+set_exception_handler(new ExceptionHandler());
b74969
+
b74969
+// exception must be throwed from error handler.
b74969
+set_error_handler(function()
b74969
+{
b74969
+	$e = new Exception;
b74969
+	$e->_trace = debug_backtrace();
b74969
+	
b74969
+	throw $e;
b74969
+});
b74969
+
b74969
+// trigger error handler
b74969
+$a['waa'];
b74969
+?>
b74969
+--EXPECTF--
b74969
+Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in %sbug64960.php on line 3
b74969
+
b74969
+Fatal error: Uncaught exception 'Exception' in %sbug64960.php:19
b74969
+Stack trace:
b74969
+#0 [internal function]: {closure}(8, 'ob_end_clean():...', '%s', 9, Array)
b74969
+#1 %sbug64960.php(9): ob_end_clean()
b74969
+#2 [internal function]: ExceptionHandler->__invoke(Object(Exception))
b74969
+#3 {main}
b74969
+  thrown in %sbug64960.php on line 19
b74969
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
b74969
index 9781889..687520d 100644
b74969
--- a/Zend/zend_execute_API.c
b74969
+++ b/Zend/zend_execute_API.c
b74969
@@ -263,15 +263,13 @@ void shutdown_executor(TSRMLS_D) /* {{{ */
b74969
 		if (EG(user_error_handler)) {
b74969
 			zeh = EG(user_error_handler);
b74969
 			EG(user_error_handler) = NULL;
b74969
-			zval_dtor(zeh);
b74969
-			FREE_ZVAL(zeh);
b74969
+			zval_ptr_dtor(&zeh;;
b74969
 		}
b74969
 
b74969
 		if (EG(user_exception_handler)) {
b74969
 			zeh = EG(user_exception_handler);
b74969
 			EG(user_exception_handler) = NULL;
b74969
-			zval_dtor(zeh);
b74969
-			FREE_ZVAL(zeh);
b74969
+			zval_ptr_dtor(&zeh;;
b74969
 		}
b74969
 
b74969
 		zend_stack_destroy(&EG(user_error_handlers_error_reporting));
b74969
-- 
b74969
1.7.11.5
b74969