From: Nikita Popov Date: Sat, 25 Nov 2017 12:31:18 +0000 (+0100) Subject: Make sure string property/class const values are interned X-Git-Tag: php-7.3.0alpha1~953 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8795893f4f90a344cc9a9d48523b7aa0ba5ebf05;p=php Make sure string property/class const values are interned This was done for user-definde class constant values, however this is also important for properties and internal classes. --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 03a0df947e..53eca994a6 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3616,6 +3616,16 @@ ZEND_API const char *zend_get_module_version(const char *module_name) /* {{{ */ } /* }}} */ +static inline zend_string *zval_make_interned_string(zval *zv) /* {{{ */ +{ + ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); + Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv)); + if (ZSTR_IS_INTERNED(Z_STR_P(zv))) { + Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE); + } + return Z_STR_P(zv); +} + ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment) /* {{{ */ { zend_property_info *property_info, *property_info_ptr; @@ -3632,6 +3642,10 @@ ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, z } } + if (Z_TYPE_P(property) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR_P(property))) { + zval_make_interned_string(property); + } + if (!(access_type & ZEND_ACC_PPP_MASK)) { access_type |= ZEND_ACC_PUBLIC; } @@ -3774,6 +3788,10 @@ ZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *n "A class constant must not be called 'class'; it is reserved for class name fetching"); } + if (Z_TYPE_P(value) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR_P(value))) { + zval_make_interned_string(value); + } + if (ce->type == ZEND_INTERNAL_CLASS) { c = pemalloc(sizeof(zend_class_constant), 1); } else { diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 4381a2492f..d4ec431f66 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6064,9 +6064,6 @@ void zend_compile_class_const_decl(zend_ast *ast) /* {{{ */ } zend_const_expr_to_zval(&value_zv, value_ast); - if (Z_TYPE(value_zv) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR(value_zv))) { - zval_make_interned_string(&value_zv); - } zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment); } }