From a015fa83a735da7342dd7ae172c4516265bed41d Mon Sep 17 00:00:00 2001 From: Arpad Ray Date: Fri, 19 Jul 2013 19:19:48 +0100 Subject: [PATCH 1/2] Fixed bug #65291 - get_defined_constants() crash with __CLASS__ in trait --- NEWS | 2 ++ Zend/tests/bug65291.phpt | 24 ++++++++++++++++++++++++ Zend/zend_builtin_functions.c | 5 +++++ 3 files changed, 31 insertions(+) create mode 100644 Zend/tests/bug65291.phpt diff --git a/NEWS b/NEWS index 4826d0ca98ad..011b3d890b79 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS - Core. . Improve fix for bug #63186 (compile failure on netbsd). (Matteo) + . Fixed bug #65291 (get_defined_constants() causes PHP to crash in a very + limited case). (Arpad) - Session: . Fixed bug #62129 (rfc1867 crashes php even though turned off). (gxd305 at diff --git a/Zend/tests/bug65291.phpt b/Zend/tests/bug65291.phpt new file mode 100644 index 000000000000..9e5cca5c3578 --- /dev/null +++ b/Zend/tests/bug65291.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #65291 - get_defined_constants() causes PHP to crash in a very limited case. +--FILE-- + +--EXPECT-- +Tester diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index f29676bac0c2..1aba64e10282 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1926,6 +1926,11 @@ static int add_constant_info(zend_constant *constant, void *arg TSRMLS_DC) zval *name_array = (zval *)arg; zval *const_val; + if (!constant->name) { + /* skip special constants */ + return 0; + } + MAKE_STD_ZVAL(const_val); *const_val = constant->value; zval_copy_ctor(const_val); From b963249456b043dba4a73cc6591d0eef11cebfbb Mon Sep 17 00:00:00 2001 From: Arpad Ray Date: Sat, 20 Jul 2013 11:05:13 +0100 Subject: [PATCH 2/2] Fixed bug #65291 - get_defined_constants() crash with __CLASS__ in trait Also fix and test for get_defined_constants(true) --- Zend/tests/bug65291.phpt | 1 + Zend/zend_builtin_functions.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Zend/tests/bug65291.phpt b/Zend/tests/bug65291.phpt index 9e5cca5c3578..7bc76331c0a8 100644 --- a/Zend/tests/bug65291.phpt +++ b/Zend/tests/bug65291.phpt @@ -17,6 +17,7 @@ class Tester $foo = Tester::testStaticFunction(); get_defined_constants(); +get_defined_constants(true); echo $foo; ?> diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 1aba64e10282..dc496e9ed5e4 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1998,11 +1998,16 @@ 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) { + /* skip special constants */ + goto next_constant; + } + if (val->module_number == PHP_USER_CONSTANT) { module_number = i; } else if (val->module_number > i || val->module_number < 0) { /* should not happen */ - goto bad_module_id; + goto next_constant; } else { module_number = val->module_number; } @@ -2019,7 +2024,7 @@ ZEND_FUNCTION(get_defined_constants) INIT_PZVAL(const_val); add_assoc_zval_ex(modules[module_number], val->name, val->name_len, const_val); -bad_module_id: +next_constant: zend_hash_move_forward_ex(EG(zend_constants), &pos); } efree(module_names);