Skip to content

Commit 70d24d3

Browse files
committed
Fix a NULL pointer dereference of spl_ptr_llist_offset()
spl_ptr_llist_offset() will return NULL when offset is invalid. However in the function zim_SplDoublyLinkedList_add(), the return value of spl_ptr_llist_offset() is directly used without check, which could lead to possible NULL pointer dereference. Fix this bug by adding the check of spl_ptr_llist_offset() like others. This bug is found by a static analyzer, making it hard to reproduce.
1 parent 0e6d6f8 commit 70d24d3

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

ext/spl/spl_dllist.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,7 @@ PHP_METHOD(SplDoublyLinkedList, add)
12571257

12581258
/* Get the element we want to insert before */
12591259
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
1260+
ZEND_ASSERT(element != NULL);
12601261

12611262
ZVAL_COPY_VALUE(&elem->data, value);
12621263
SPL_LLIST_RC(elem) = 1;

0 commit comments

Comments
 (0)