Skip to content

Commit 1b8be9a

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
2 parents 4269f04 + 40ccc8e commit 1b8be9a

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
. Fixed bug GH-12870 (Creating an xmlns attribute results in a DOMException).
1515
(nielsdos)
1616

17+
- FFI:
18+
. Fixed bug GH-9698 (stream_wrapper_register crashes with FFI\CData).
19+
(Jakub Zelenka)
20+
1721
- Hash:
1822
. Fixed bug GH-12936 (hash() function hangs endlessly if using sha512 on
1923
strings >= 4GiB). (nielsdos)

ext/ffi/ffi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,10 @@ static zval *zend_ffi_cdata_write_field(zend_object *obj, zend_string *field_nam
13021302
if (cache_slot && *cache_slot == type) {
13031303
field = *(cache_slot + 1);
13041304
} else {
1305+
if (UNEXPECTED(type == NULL)) {
1306+
zend_throw_error(zend_ffi_exception_ce, "Attempt to assign field '%s' to uninitialized FFI\\CData object", ZSTR_VAL(field_name));
1307+
return value;
1308+
}
13051309
if (type->kind == ZEND_FFI_TYPE_POINTER) {
13061310
type = ZEND_FFI_TYPE(type->pointer.type);
13071311
}

ext/ffi/tests/gh9698.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-9698 (stream_wrapper_register crashes with FFI\CData provided as class)
3+
--EXTENSIONS--
4+
ffi
5+
--SKIPIF--
6+
<?php
7+
?>
8+
--FILE--
9+
<?php
10+
try {
11+
stream_wrapper_register('badffi', 'FFI\CData');
12+
file_get_contents('badffi://x');
13+
} catch (Throwable $exception) {
14+
echo $exception->getMessage();
15+
}
16+
?>
17+
18+
DONE
19+
--EXPECT--
20+
Attempt to assign field 'context' to uninitialized FFI\CData object
21+
DONE

main/streams/userspace.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php
278278
add_property_null(object, "context");
279279
}
280280

281+
if (EG(exception) != NULL) {
282+
zval_ptr_dtor(object);
283+
ZVAL_UNDEF(object);
284+
return;
285+
}
286+
281287
if (uwrap->ce->constructor) {
282288
zend_call_known_instance_method_with_0_params(
283289
uwrap->ce->constructor, Z_OBJ_P(object), NULL);

0 commit comments

Comments
 (0)