1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

zend_hash: Assert that the interned parameter is not a lie (#19843)

* zend_hash: Assert that the `interned` parameter is not a lie

While investigating php/php-src#19842 I was wondering why non-interned string
didn't cause troubles, until I realized it was the value instead of the key.
Nevertheless it appears useful to check that the key is actually interned as
claimed by the caller to prevent hard-to-find bugs.

* zend_hash: Rename `interned` parameter name to `key_guaranteed_interned`
This commit is contained in:
Tim Düsterhus
2025-09-16 10:51:07 +02:00
committed by GitHub
parent 1644af21dd
commit 28fc06be49

View File

@@ -1621,14 +1621,15 @@ static zend_always_inline bool zend_array_is_list(const zend_array *array)
}
static zend_always_inline zval *_zend_hash_append_ex(HashTable *ht, zend_string *key, zval *zv, bool interned)
static zend_always_inline zval *_zend_hash_append_ex(HashTable *ht, zend_string *key, zval *zv, bool key_guaranteed_interned)
{
uint32_t idx = ht->nNumUsed++;
uint32_t nIndex;
Bucket *p = ht->arData + idx;
ZVAL_COPY_VALUE(&p->val, zv);
if (!interned && !ZSTR_IS_INTERNED(key)) {
ZEND_ASSERT(!key_guaranteed_interned || ZSTR_IS_INTERNED(key));
if (!key_guaranteed_interned && !ZSTR_IS_INTERNED(key)) {
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
zend_string_addref(key);
zend_string_hash_val(key);
@@ -1647,14 +1648,15 @@ static zend_always_inline zval *_zend_hash_append(HashTable *ht, zend_string *ke
return _zend_hash_append_ex(ht, key, zv, 0);
}
static zend_always_inline zval *_zend_hash_append_ptr_ex(HashTable *ht, zend_string *key, void *ptr, bool interned)
static zend_always_inline zval *_zend_hash_append_ptr_ex(HashTable *ht, zend_string *key, void *ptr, bool key_guaranteed_interned)
{
uint32_t idx = ht->nNumUsed++;
uint32_t nIndex;
Bucket *p = ht->arData + idx;
ZVAL_PTR(&p->val, ptr);
if (!interned && !ZSTR_IS_INTERNED(key)) {
ZEND_ASSERT(!key_guaranteed_interned || ZSTR_IS_INTERNED(key));
if (!key_guaranteed_interned && !ZSTR_IS_INTERNED(key)) {
HT_FLAGS(ht) &= ~HASH_FLAG_STATIC_KEYS;
zend_string_addref(key);
zend_string_hash_val(key);