From: Sara Golemon Date: Wed, 12 Oct 2016 04:35:10 +0000 (-0700) Subject: Clear FG(user_stream_current_filename) when bailing out X-Git-Tag: php-7.2.0alpha1~1167^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f86cdaf7fc44c0d97a35bc4d04622e3d3d53f4d;p=php Clear FG(user_stream_current_filename) when bailing out 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 --- diff --git a/ext/standard/tests/streams/user-stream-error.phpt b/ext/standard/tests/streams/user-stream-error.phpt new file mode 100644 index 0000000000..bfa625be2c --- /dev/null +++ b/ext/standard/tests/streams/user-stream-error.phpt @@ -0,0 +1,23 @@ +--TEST-- +E_ERROR during UserStream Open +--FILE-- +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 diff --git a/main/streams/userspace.c b/main/streams/userspace.c index eb8b32eed9..6afa3b095c 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -370,12 +370,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! */