php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch Patch-for-65291 for Reproducible crash Bug #65291

Patch version 2013-07-20 03:50 UTC

Return to Bug #65291 | Download this patch
Patch Revisions:

Developer: reeze@php.net

From d7430c7d69b947bb4526eb38f41f0da4953d503c Mon Sep 17 00:00:00 2001
From: Reeze Xia <reeze@php.net>
Date: Sat, 20 Jul 2013 11:47:35 +0800
Subject: [PATCH] Fixed bug #65291 (get_defined_constants() crash with
 __CLASS__ in trait)


Signed-off-by: Reeze Xia <reeze@php.net>
---
 Zend/tests/bug65291.phpt      | 24 ++++++++++++++++++++++++
 Zend/zend_builtin_functions.c | 17 ++++++++++++-----
 2 files changed, 36 insertions(+), 5 deletions(-)
 create mode 100644 Zend/tests/bug65291.phpt

diff --git a/Zend/tests/bug65291.phpt b/Zend/tests/bug65291.phpt
new file mode 100644
index 0000000..006c02a
--- /dev/null
+++ b/Zend/tests/bug65291.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #65291 (get_defined_constants() crash with __CLASS__ in trait)
+--FILE--
+<?php
+
+trait TestTrait
+{
+	public static function testStaticFunction()
+	{
+		return __CLASS__;
+	}
+}
+class Tester
+{
+	use TestTrait;
+}
+$tester = Tester::testStaticFunction();
+
+get_defined_constants();
+get_defined_constants(true);
+echo "It Worked!";
+?>
+--EXPECTF--
+It Worked!
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index f29676b..6b84c74 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1926,11 +1926,13 @@ static int add_constant_info(zend_constant *constant, void *arg TSRMLS_DC)
 	zval *name_array = (zval *)arg;
 	zval *const_val;
 
-	MAKE_STD_ZVAL(const_val);
-	*const_val = constant->value;
-	zval_copy_ctor(const_val);
-	INIT_PZVAL(const_val);
-	add_assoc_zval_ex(name_array, constant->name, constant->name_len, const_val);
+	if (constant->name_len > 0) {
+		MAKE_STD_ZVAL(const_val);
+		*const_val = constant->value;
+		zval_copy_ctor(const_val);
+		INIT_PZVAL(const_val);
+		add_assoc_zval_ex(name_array, constant->name, constant->name_len, const_val);
+	}
 	return 0;
 }
 
@@ -1993,6 +1995,10 @@ ZEND_FUNCTION(get_defined_constants)
 		while (zend_hash_get_current_data_ex(EG(zend_constants), (void **) &val, &pos) != FAILURE) {
 			zval *const_val;
 
+			if (val->name_len == 0) {
+				goto continue_loop;
+			}
+
 			if (val->module_number == PHP_USER_CONSTANT) {
 				module_number = i;
 			} else if (val->module_number > i || val->module_number < 0) {
@@ -2014,6 +2020,7 @@ ZEND_FUNCTION(get_defined_constants)
 			INIT_PZVAL(const_val);
 
 			add_assoc_zval_ex(modules[module_number], val->name, val->name_len, const_val);
+continue_loop:
 bad_module_id:
 			zend_hash_move_forward_ex(EG(zend_constants), &pos);
 		}
-- 
1.8.1.3

 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 08:02:55 2014 UTC