Skip to content

Commit e0b1b69

Browse files
committed
Fix OSS-Fuzz #371445205: Heap-use-after-free in attr_free
zend_hash_get_current_key() does not return a string with incremented refcount, so it shouldn't get released. This release caused a UAF later when the attribute was destroyed. This wasn't noticed earlier because object_init_with_constructor() was only ever tested with interned strings. Closes GH-16349.
1 parent 25d0661 commit e0b1b69

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- COM:
66
. Fixed out of bound writes to SafeArray data. (cmb)
77

8+
- Core:
9+
. Fixed bug OSS-Fuzz #371445205 (Heap-use-after-free in attr_free).
10+
(nielsdos)
11+
812
- Curl:
913
. Fixed bug GH-16302 (CurlMultiHandle holds a reference to CurlHandle if
1014
curl_multi_add_handle fails). (timwolla)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
OSS-Fuzz #371445205 (Heap-use-after-free in attr_free)
3+
--FILE--
4+
<?php
5+
#[Attribute]
6+
class MyAttrib{}
7+
#[MyAttrib(notinterned:'')]
8+
class Test1{}
9+
$attr=(new ReflectionClass(Test1::class))->getAttributes()[0];
10+
try {
11+
$attr->newInstance();
12+
} catch (Error $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
?>
16+
--EXPECT--
17+
Unknown named parameter $notinterned

Zend/zend_API.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,6 @@ ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *c
18791879
zend_hash_get_current_key(named_params, &arg_name, /* num_index */ NULL);
18801880
ZEND_ASSERT(arg_name != NULL);
18811881
zend_throw_error(NULL, "Unknown named parameter $%s", ZSTR_VAL(arg_name));
1882-
zend_string_release(arg_name);
18831882
/* Do not call destructor, free object, and set arg to IS_UNDEF */
18841883
zend_object_store_ctor_failed(obj);
18851884
zval_ptr_dtor(arg);

0 commit comments

Comments
 (0)