com php-src: Fix invalid free on undef const in update_const (): Zend/zend_execute_API.c
| From: | Nikita Popov | Date: | Fri, 29 Jul 2016 22:37:01 +0000 |
| Subject: | com php-src: Fix invalid free on undef const in update_const (): Zend/zend_execute_API.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93482@lists.php.net to get a copy of this message | ||
Commit: ca82574d7cefb05b15e13d0b91eb86b3dffa323f
Author: Nikita Popov <nikic@php.net> Sat, 30 Jul 2016 00:36:06 +0200
Parents: 11e050920d3052d2b14a9cff6c4c5764d674fc46
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ca82574d7cefb05b15e13d0b91eb86b3dffa323f
Log:
Fix invalid free on undef const in update_const()
Also clean up the control flow a bit -- move all unqualified
constant handling in one branch.
Changed paths:
M Zend/zend_execute_API.c
Diff:
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index c039bb8..3432064 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -597,26 +597,24 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{
*/
RESET_CONSTANT_VISITED(p);
return FAILURE;
} else {
- zend_string *save = Z_STR_P(p);
- char *slash;
- size_t actual_len = Z_STRLEN_P(p);
- if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) && (slash = (char
*)zend_memrchr(actual, '\\', actual_len))) {
- actual = slash + 1;
- actual_len -= (actual - Z_STRVAL_P(p));
- if (inline_change) {
- zend_string *s = zend_string_init(actual, actual_len, 0);
- Z_STR_P(p) = s;
- Z_TYPE_FLAGS_P(p) = IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE;
- }
- }
if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
- zend_throw_error(NULL, "Undefined constant '%s'", ZSTR_VAL(save));
- if (inline_change) {
- zend_string_release(save);
- }
+ zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(p));
RESET_CONSTANT_VISITED(p);
return FAILURE;
} else {
+ zend_string *save = Z_STR_P(p);
+ size_t actual_len = Z_STRLEN_P(p);
+ char *slash = (char *) zend_memrchr(actual, '\\', actual_len);
+ if (slash) {
+ actual = slash + 1;
+ actual_len -= (actual - Z_STRVAL_P(p));
+ if (inline_change) {
+ zend_string *s = zend_string_init(actual, actual_len, 0);
+ Z_STR_P(p) = s;
+ Z_TYPE_FLAGS_P(p) = IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE;
+ }
+ }
+
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
actual, actual);
if (!inline_change) {
ZVAL_STRINGL(p, actual, actual_len);