Skip to content

Commit d43d468

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-18018: RC1 data returned from offsetGet causes UAF in ArrayObject
2 parents 0c0cebe + 27affd8 commit d43d468

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ PHP NEWS
4444
. Fixed bug GH-17984 (calls with arguments as array with references).
4545
(David Carlier)
4646

47+
- SPL:
48+
. Fixed bug GH-18018 (RC1 data returned from offsetGet causes UAF in
49+
ArrayObject). (nielsdos)
50+
4751
- Treewide:
4852
. Fixed bug GH-17736 (Assertion failure zend_reference_destroy()). (nielsdos)
4953

ext/spl/spl_array.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,14 @@ static bool spl_array_has_dimension_ex(bool check_inherited, zend_object *object
665665
}
666666
}
667667

668+
/* empty() check the value is not falsy, isset() only check it is not null */
669+
bool result = check_empty ? zend_is_true(value) : Z_TYPE_P(value) != IS_NULL;
670+
668671
if (value == &rv) {
669672
zval_ptr_dtor(&rv);
670673
}
671674

672-
/* empty() check the value is not falsy, isset() only check it is not null */
673-
return check_empty ? zend_is_true(value) : Z_TYPE_P(value) != IS_NULL;
675+
return result;
674676
} /* }}} */
675677

676678
static int spl_array_has_dimension(zend_object *object, zval *offset, int check_empty) /* {{{ */

ext/spl/tests/gh18018.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-18018 (RC1 data returned from offsetGet causes UAF in ArrayObject)
3+
--FILE--
4+
<?php
5+
class Crap extends ArrayObject
6+
{
7+
public function offsetGet($offset): mixed
8+
{
9+
return [random_int(1,1)];
10+
}
11+
}
12+
13+
$values = ['qux' => 1];
14+
15+
$object = new Crap($values);
16+
17+
var_dump(empty($object['qux']));
18+
?>
19+
--EXPECT--
20+
bool(false)

0 commit comments

Comments
 (0)