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