Skip to content

Commit 8a2a69a

Browse files
committed
Fix possibility of a wrong element being deleted by zend_hash_del()
1 parent 8a05386 commit 8a2a69a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Zend/zend_hash.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,11 @@ ZEND_API int zend_u_hash_del_key_or_index(HashTable *ht, zend_uchar type, void *
546546

547547
p = ht->arBuckets[nIndex];
548548
while (p != NULL) {
549-
if ((p->h == h) &&
550-
((p->nKeyLength == 0) || /* Numeric index */
551-
((p->nKeyLength == nKeyLength) &&
552-
(p->key.type == type) &&
553-
(!memcmp(&p->key.u, arKey, realKeyLength))))) {
549+
if ((p->h == h)
550+
&& (p->nKeyLength == nKeyLength)
551+
&& ((p->nKeyLength == 0) /* Numeric index (short circuits the memcmp()) */
552+
|| ((p->key.type == type)
553+
&& !memcmp(&p->key.u, arKey, realKeyLength)))) {
554554
HANDLE_BLOCK_INTERRUPTIONS();
555555
if (p == ht->arBuckets[nIndex]) {
556556
ht->arBuckets[nIndex] = p->pNext;

0 commit comments

Comments
 (0)