Fixed string interning during constants substitution

This commit is contained in:
Dmitry Stogov 2017-11-01 10:34:39 +03:00
parent a8a17a72b0
commit e0924c52fc
3 changed files with 30 additions and 9 deletions

View file

@ -0,0 +1,12 @@
--TEST--
String interning during constants substitution
--INI--
opcache.enable_cli=0
--FILE--
<?php
define ("A", "." . ord(26) . ".");
eval("class A {const a = A;}");
var_dump(A::a);
?>
--EXPECT--
string(4) ".50."

View file

@ -445,13 +445,21 @@ ZEND_API zend_constant* ZEND_FASTCALL zend_quick_get_constant(const zval *key, u
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)
{
void *ret;
zend_constant *copy = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);
zval *ret, tmp;
zend_constant *copy;
memcpy(copy, c, sizeof(zend_constant));
ret = zend_hash_add_ptr(ht, key, copy);
if (!ret) {
pefree(copy, c->flags & CONST_PERSISTENT);
ZVAL_PTR(&tmp, NULL);
ret = zend_hash_add(ht, key, &tmp);
if (EXPECTED(ret)) {
Z_PTR_P(ret) = copy = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);
memcpy(copy, c, sizeof(zend_constant));
if (Z_TYPE(copy->value) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR(copy->value))) {
SEPARATE_STRING(&copy->value);
Z_STR(copy->value) = zend_new_interned_string(Z_STR(copy->value));
if (ZSTR_IS_INTERNED(Z_STR(copy->value))) {
Z_TYPE_FLAGS(copy->value) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
}
}
}
return ret;
}
@ -466,9 +474,7 @@ ZEND_API int zend_register_constant(zend_constant *c)
printf("Registering constant for module %d\n", c->module_number);
#endif
if (c->module_number != PHP_USER_CONSTANT) {
c->name = zend_new_interned_string(c->name);
}
c->name = zend_new_interned_string(c->name);
if (!(c->flags & CONST_CS)) {
lowercase_name = zend_string_alloc(ZSTR_LEN(c->name), c->flags & CONST_PERSISTENT);

View file

@ -644,6 +644,9 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int
if (c->name) {
c->name = new_interned_string(c->name);
}
if (Z_TYPE(c->value) == IS_STRING) {
Z_STR(c->value) = new_interned_string(Z_STR(c->value));
}
} ZEND_HASH_FOREACH_END();
/* auto globals hash keys and names */