Skip to content

Commit e2189be

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix phpGH-14639: Member access within null pointer in ext/spl/spl_observer.c
2 parents 776939c + 8ea3f15 commit e2189be

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

ext/spl/spl_observer.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ static void spl_object_storage_free_hash(spl_SplObjectStorage *intern, zend_hash
115115
static void spl_object_storage_dtor(zval *element) /* {{{ */
116116
{
117117
spl_SplObjectStorageElement *el = Z_PTR_P(element);
118-
zend_object_release(el->obj);
119-
zval_ptr_dtor(&el->inf);
120-
efree(el);
118+
if (el) {
119+
zend_object_release(el->obj);
120+
zval_ptr_dtor(&el->inf);
121+
efree(el);
122+
}
121123
} /* }}} */
122124

123125
static spl_SplObjectStorageElement* spl_object_storage_get(spl_SplObjectStorage *intern, zend_hash_key *key) /* {{{ */
@@ -165,8 +167,10 @@ static spl_SplObjectStorageElement *spl_object_storage_attach_handle(spl_SplObje
165167
return pelement;
166168
}
167169

170+
/* NULL initialization necessary because `spl_object_storage_create_element` could bail out due to OOM. */
171+
ZVAL_PTR(entry_zv, NULL);
168172
pelement = spl_object_storage_create_element(obj, inf);
169-
ZVAL_PTR(entry_zv, pelement);
173+
Z_PTR_P(entry_zv) = pelement;
170174
return pelement;
171175
} /* }}} */
172176

ext/spl/tests/gh14639.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-14639 (Member access within null pointer in ext/spl/spl_observer.c)
3+
--INI--
4+
memory_limit=2M
5+
--SKIPIF--
6+
<?php
7+
if (getenv("USE_ZEND_ALLOC") === "0") {
8+
die("skip Zend MM disabled");
9+
}
10+
?>
11+
--FILE--
12+
<?php
13+
$b = new SplObjectStorage();
14+
for ($i = 10000; $i > 0; $i--) {
15+
$object = new StdClass();
16+
$object->a = str_repeat("a", 2);
17+
$b->attach($object);
18+
}
19+
?>
20+
--EXPECTF--
21+
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d

0 commit comments

Comments
 (0)