Skip to content

Commit b73349d

Browse files
committed
Fix possibility of a wrong element being deleted by zend_hash_del()
Thanks Stefan!
1 parent 0249f6b commit b73349d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Zend/zend_hash.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,10 @@ ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLen
461461

462462
p = ht->arBuckets[nIndex];
463463
while (p != NULL) {
464-
if ((p->h == h) && ((p->nKeyLength == 0) || /* Numeric index */
465-
((p->nKeyLength == nKeyLength) && (!memcmp(p->arKey, arKey, nKeyLength))))) {
464+
if ((p->h == h)
465+
&& (p->nKeyLength == nKeyLength)
466+
&& ((p->nKeyLength == 0) /* Numeric index (short circuits the memcmp() check) */
467+
|| !memcmp(p->arKey, arKey, nKeyLength))) { /* String index */
466468
HANDLE_BLOCK_INTERRUPTIONS();
467469
if (p == ht->arBuckets[nIndex]) {
468470
ht->arBuckets[nIndex] = p->pNext;

0 commit comments

Comments
 (0)