Skip to content

Commit c599c18

Browse files
committed
Merge branch 'PHP-7.3'
* PHP-7.3: Update NEWS Fixed bug #77664 (Segmentation fault when using undefined constant in custom wrapper)
2 parents 7a564fc + 3b5475e commit c599c18

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
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
@@ -287,7 +287,10 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php
287287
}
288288

289289
/* create an instance of our class */
290-
object_init_ex(object, uwrap->ce);
290+
if (object_init_ex(object, uwrap->ce) == FAILURE) {
291+
ZVAL_UNDEF(object);
292+
return;
293+
}
291294

292295
if (context) {
293296
add_property_resource(object, "context", context->res);

0 commit comments

Comments
 (0)