Skip to content

Commit 4b95210

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 4b95210

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ext/spl/spl_dllist.c

+4
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,10 @@ 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+
if (element == NULL) {
1261+
zend_argument_error(spl_ce_OutOfRangeException, 1, "is an invalid offset");
1262+
RETURN_THROWS();
1263+
}
12601264

12611265
ZVAL_COPY_VALUE(&elem->data, value);
12621266
SPL_LLIST_RC(elem) = 1;

0 commit comments

Comments
 (0)