]> granicus.if.org Git - php/commitdiff
Make sure string property/class const values are interned
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 25 Nov 2017 12:31:18 +0000 (13:31 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 25 Nov 2017 16:12:37 +0000 (17:12 +0100)
This was done for user-definde class constant values, however this
is also important for properties and internal classes.

Zend/zend_API.c
Zend/zend_compile.c

index 03a0df947e3bb4270f0826bd8418898de83c7987..53eca994a65aba4defc9dffcf9d98057833429e5 100644 (file)
@@ -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 {
index 4381a2492f1c579011cbfdb6e25789bc2a3bd058..d4ec431f669b1d3561ac00131730f039a39ed7c8 100644 (file)
@@ -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);
        }
 }