Skip to content

Commit 8795893

Browse files
committed
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.
1 parent c5767db commit 8795893

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Zend/zend_API.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,6 +3616,16 @@ ZEND_API const char *zend_get_module_version(const char *module_name) /* {{{ */
36163616
}
36173617
/* }}} */
36183618

3619+
static inline zend_string *zval_make_interned_string(zval *zv) /* {{{ */
3620+
{
3621+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
3622+
Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv));
3623+
if (ZSTR_IS_INTERNED(Z_STR_P(zv))) {
3624+
Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
3625+
}
3626+
return Z_STR_P(zv);
3627+
}
3628+
36193629
ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment) /* {{{ */
36203630
{
36213631
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
36323642
}
36333643
}
36343644

3645+
if (Z_TYPE_P(property) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR_P(property))) {
3646+
zval_make_interned_string(property);
3647+
}
3648+
36353649
if (!(access_type & ZEND_ACC_PPP_MASK)) {
36363650
access_type |= ZEND_ACC_PUBLIC;
36373651
}
@@ -3774,6 +3788,10 @@ ZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *n
37743788
"A class constant must not be called 'class'; it is reserved for class name fetching");
37753789
}
37763790

3791+
if (Z_TYPE_P(value) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR_P(value))) {
3792+
zval_make_interned_string(value);
3793+
}
3794+
37773795
if (ce->type == ZEND_INTERNAL_CLASS) {
37783796
c = pemalloc(sizeof(zend_class_constant), 1);
37793797
} else {

Zend/zend_compile.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6064,9 +6064,6 @@ void zend_compile_class_const_decl(zend_ast *ast) /* {{{ */
60646064
}
60656065

60666066
zend_const_expr_to_zval(&value_zv, value_ast);
6067-
if (Z_TYPE(value_zv) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR(value_zv))) {
6068-
zval_make_interned_string(&value_zv);
6069-
}
60706067
zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment);
60716068
}
60726069
}

0 commit comments

Comments
 (0)