Skip to content

Commit b711a96

Browse files
committed
Don't keep HashTable.pDestructor in SHM and always set it into ZVAL_PTR_DTOR in zval_array_dup().
Keeping pointer to a function in SHM is not safe because of ASLR.
1 parent 033ce8f commit b711a96

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Zend/zend_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
17651765
GC_TYPE_INFO(target) = IS_ARRAY;
17661766

17671767
target->nTableSize = source->nTableSize;
1768-
target->pDestructor = source->pDestructor;
1768+
target->pDestructor = ZVAL_PTR_DTOR;
17691769

17701770
if (source->nNumUsed == 0) {
17711771
target->u.flags = (source->u.flags & ~(HASH_FLAG_INITIALIZED|HASH_FLAG_PACKED|HASH_FLAG_PERSISTENT|ZEND_HASH_APPLY_COUNT_MASK)) | HASH_FLAG_APPLY_PROTECTION | HASH_FLAG_STATIC_KEYS;

ext/opcache/zend_persist.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement
8686
uint32_t idx, nIndex;
8787
Bucket *p;
8888

89+
ht->pDestructor = NULL;
90+
8991
if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) {
9092
HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
9193
return;
@@ -170,6 +172,8 @@ static void zend_hash_persist_immutable(HashTable *ht)
170172
uint32_t idx, nIndex;
171173
Bucket *p;
172174

175+
ht->pDestructor = NULL;
176+
173177
if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) {
174178
HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
175179
return;

0 commit comments

Comments
 (0)