]> granicus.if.org Git - php/commitdiff
Clear FG(user_stream_current_filename) when bailing out
authorSara Golemon <pollita@php.net>
Wed, 12 Oct 2016 04:35:10 +0000 (21:35 -0700)
committerSara Golemon <pollita@php.net>
Wed, 12 Oct 2016 04:44:14 +0000 (21:44 -0700)
If a userwrapper opener E_ERRORs then FG(user_stream_current_filename)
would remain set until the next request and would not be pointing
at unallocated memory.

Catch the bailout, clear the variable, then continue bailing.

Closes https://bugs.php.net/bug.php?id=73188

ext/standard/tests/streams/user-stream-error.phpt [new file with mode: 0644]
main/streams/userspace.c

diff --git a/ext/standard/tests/streams/user-stream-error.phpt b/ext/standard/tests/streams/user-stream-error.phpt
new file mode 100644 (file)
index 0000000..bfa625b
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+E_ERROR during UserStream Open
+--FILE--
+<?php
+
+class FailStream {
+  public function stream_open($path, $mode, $options, &$opened_path) {
+    _some_undefined_function();
+  }
+}
+stream_wrapper_register('mystream', 'FailStream');
+fopen('mystream://foo', 'r');
+echo 'Done';
+
+--EXPECTF--
+Warning: fopen(mystream://foo): failed to open stream: "FailStream::stream_open" call failed in %s/user-stream-error.php on line %d
+
+Fatal error: Uncaught Error: Call to undefined function _some_undefined_function() in %s/user-stream-error.php:%d
+Stack trace:
+#0 [internal function]: FailStream->stream_open('mystream://foo', 'r', 0, NULL)
+#1 %s/user-stream-error.php(%d): fopen('mystream://foo', 'r')
+#2 {main}
+  thrown in %s/user-stream-error.php on line %d
index 63a351a59b321ddd75b6c3e44c445b628ee9ffc6..504f4d72827c852e7e3788957d5c81af1e762476 100644 (file)
@@ -372,12 +372,17 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
 
        ZVAL_STRING(&zfuncname, USERSTREAM_OPEN);
 
-       call_result = call_user_function_ex(NULL,
-                       Z_ISUNDEF(us->object)? NULL : &us->object,
-                       &zfuncname,
-                       &zretval,
-                       4, args,
-                       0, NULL );
+       zend_try {
+               call_result = call_user_function_ex(NULL,
+                               Z_ISUNDEF(us->object)? NULL : &us->object,
+                               &zfuncname,
+                               &zretval,
+                               4, args,
+                               0, NULL );
+       } zend_catch {
+               FG(user_stream_current_filename) = NULL;
+               zend_bailout();
+       } zend_end_try();
 
        if (call_result == SUCCESS && Z_TYPE(zretval) != IS_UNDEF && zval_is_true(&zretval)) {
                /* the stream is now open! */