diff --git a/NEWS b/NEWS index 7f7a616bc1c..4cb6bbb0912 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,10 @@ PHP NEWS . Fixed bug GH-17984 (calls with arguments as array with references). (David Carlier) +- SPL: + . Fixed bug GH-18018 (RC1 data returned from offsetGet causes UAF in + ArrayObject). (nielsdos) + - Treewide: . Fixed bug GH-17736 (Assertion failure zend_reference_destroy()). (nielsdos) diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 14c31bd42ab..49ed0567711 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -665,12 +665,14 @@ static bool spl_array_has_dimension_ex(bool check_inherited, zend_object *object } } + /* empty() check the value is not falsy, isset() only check it is not null */ + bool result = check_empty ? zend_is_true(value) : Z_TYPE_P(value) != IS_NULL; + if (value == &rv) { zval_ptr_dtor(&rv); } - /* empty() check the value is not falsy, isset() only check it is not null */ - return check_empty ? zend_is_true(value) : Z_TYPE_P(value) != IS_NULL; + return result; } /* }}} */ static int spl_array_has_dimension(zend_object *object, zval *offset, int check_empty) /* {{{ */ diff --git a/ext/spl/tests/gh18018.phpt b/ext/spl/tests/gh18018.phpt new file mode 100644 index 00000000000..06fa7fc3d0e --- /dev/null +++ b/ext/spl/tests/gh18018.phpt @@ -0,0 +1,20 @@ +--TEST-- +GH-18018 (RC1 data returned from offsetGet causes UAF in ArrayObject) +--FILE-- + 1]; + +$object = new Crap($values); + +var_dump(empty($object['qux'])); +?> +--EXPECT-- +bool(false)