Skip to content

Commit 4a72dd7

Browse files
committed
Fixed bug #77664 (Segmentation fault when using undefined constant in custom wrapper)
1 parent 01c0095 commit 4a72dd7

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #77652 (Anonymous classes can lose their interface information).
77
(Nikita)
88

9+
- Standard:
10+
. Fixed bug #77664 (Segmentation fault when using undefined constant in
11+
custom wrapper). (Laruence)
12+
913
- MySQLi:
1014
. Fixed bug #77597 (mysqli_fetch_field hangs scripts). (Nikita)
1115

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
BUG #77664 (Segmentation fault when using undefined constant in custom wrapper)
3+
--FILE--
4+
<?php
5+
class ErrorWrapper {
6+
public $context;
7+
public $var = self::INVALID;
8+
}
9+
stream_wrapper_register('error',ErrorWrapper::class);
10+
file_get_contents('error://test');
11+
?>
12+
--EXPECTF--
13+
Warning: file_get_contents(error://test): failed to open stream: operation failed in %sbug77664.php on line %d
14+
15+
Fatal error: Uncaught Error: Undefined class constant 'self::INVALID' in %sbug77664.php:%d
16+
Stack trace:
17+
#0 %sbug77664.php(%d): file_get_contents('error://test')
18+
#1 {main}
19+
thrown in %sbug77664.php on line %d

main/streams/userspace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,10 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php
289289
}
290290

291291
/* create an instance of our class */
292-
object_init_ex(object, uwrap->ce);
292+
if (object_init_ex(object, uwrap->ce) == FAILURE) {
293+
ZVAL_UNDEF(object);
294+
return;
295+
}
293296

294297
if (context) {
295298
add_property_resource(object, "context", context->res);

0 commit comments

Comments
 (0)