summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2019-02-25 14:40:53 +0800
committerXinchen Hui <laruence@gmail.com>2019-02-25 14:41:46 +0800
commit4a72dd782df3089a0d944a7e51eabebdf1f1abc3 (patch)
tree659323b662a850e15a03f2f5f5f05b85ca00dac3
parent01c00953ff07b3b9414c446c6872b047b23afe24 (diff)
downloadphp-git-4a72dd782df3089a0d944a7e51eabebdf1f1abc3.tar.gz
Fixed bug #77664 (Segmentation fault when using undefined constant in custom wrapper)
-rw-r--r--NEWS4
-rw-r--r--ext/standard/tests/streams/bug77664.phpt19
-rw-r--r--main/streams/userspace.c5
3 files changed, 27 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 4dac16ac25..37138ed998 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,10 @@ PHP NEWS
. Fixed bug #77652 (Anonymous classes can lose their interface information).
(Nikita)
+- Standard:
+ . Fixed bug #77664 (Segmentation fault when using undefined constant in
+ custom wrapper). (Laruence)
+
- MySQLi:
. Fixed bug #77597 (mysqli_fetch_field hangs scripts). (Nikita)
diff --git a/ext/standard/tests/streams/bug77664.phpt b/ext/standard/tests/streams/bug77664.phpt
new file mode 100644
index 0000000000..6a925417e2
--- /dev/null
+++ b/ext/standard/tests/streams/bug77664.phpt
@@ -0,0 +1,19 @@
+--TEST--
+BUG #77664 (Segmentation fault when using undefined constant in custom wrapper)
+--FILE--
+<?php
+class ErrorWrapper {
+ public $context;
+ public $var = self::INVALID;
+}
+stream_wrapper_register('error',ErrorWrapper::class);
+file_get_contents('error://test');
+?>
+--EXPECTF--
+Warning: file_get_contents(error://test): failed to open stream: operation failed in %sbug77664.php on line %d
+
+Fatal error: Uncaught Error: Undefined class constant 'self::INVALID' in %sbug77664.php:%d
+Stack trace:
+#0 %sbug77664.php(%d): file_get_contents('error://test')
+#1 {main}
+ thrown in %sbug77664.php on line %d
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index c72c7765f0..4925e41ac3 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -289,7 +289,10 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php
}
/* create an instance of our class */
- object_init_ex(object, uwrap->ce);
+ if (object_init_ex(object, uwrap->ce) == FAILURE) {
+ ZVAL_UNDEF(object);
+ return;
+ }
if (context) {
add_property_resource(object, "context", context->res);