summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-09-22 13:01:32 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-09-22 16:11:35 +0200
commit5ed0602ec622274bf5672304ae414e5ecb2e5167 (patch)
tree44771086e2884be16e5d8132bd3140be5d06466c
parent4000780b3d0bbba2d94f65602e602c3892d9775b (diff)
downloadphp-git-5ed0602ec622274bf5672304ae414e5ecb2e5167.tar.gz
Fix #76943: Inconsistent stream_wrapper_restore() errors
If restoring of any not registered built-in wrapper is requested, the function is supposed to fail with a warning, so we have to check this condition first. Furthermore, to be able to detect whether a built-in wrapper has been changed, it is not sufficient to check whether *any* userland wrapper has been registered, but rather whether the specific wrapper has been modified. Closes GH-6183.
-rw-r--r--NEWS1
-rw-r--r--ext/standard/tests/streams/bug76943.phpt28
-rw-r--r--main/streams/userspace.c13
3 files changed, 36 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 54463d4983..12a2de1385 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ PHP NEWS
- Standard:
. Fixed bug #80114 (parse_url does not accept URLs with port 0). (cmb, twosee)
+ . Fixed bug #76943 (Inconsistent stream_wrapper_restore() errors). (cmb)
01 Oct 2020, PHP 7.3.23
diff --git a/ext/standard/tests/streams/bug76943.phpt b/ext/standard/tests/streams/bug76943.phpt
new file mode 100644
index 0000000000..755c348f86
--- /dev/null
+++ b/ext/standard/tests/streams/bug76943.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Bug #76943 (Inconsistent stream_wrapper_restore() errors)
+--SKIPIF--
+<?php
+if (!in_array('phar', stream_get_wrappers())) die('skip phar wrapper not registered');
+?>
+--FILE--
+<?php
+var_dump(stream_wrapper_restore('foo'));
+var_dump(stream_wrapper_restore('phar'));
+
+stream_wrapper_register('bar', 'stdClass');
+
+var_dump(stream_wrapper_restore('foo'));
+var_dump(stream_wrapper_restore('phar'));
+?>
+--EXPECTF--
+Warning: stream_wrapper_restore(): foo:// never existed, nothing to restore in %s on line %d
+bool(false)
+
+Notice: stream_wrapper_restore(): phar:// was never changed, nothing to restore in %s on line %d
+bool(true)
+
+Warning: stream_wrapper_restore(): foo:// never existed, nothing to restore in %s on line %d
+bool(false)
+
+Notice: stream_wrapper_restore(): phar:// was never changed, nothing to restore in %s on line %d
+bool(true)
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index 3b513cb7f1..9d15310b16 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -559,23 +559,24 @@ PHP_FUNCTION(stream_wrapper_restore)
{
zend_string *protocol;
php_stream_wrapper *wrapper;
- HashTable *global_wrapper_hash;
+ HashTable *global_wrapper_hash, *wrapper_hash;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &protocol) == FAILURE) {
RETURN_FALSE;
}
global_wrapper_hash = php_stream_get_url_stream_wrappers_hash_global();
- if (php_stream_get_url_stream_wrappers_hash() == global_wrapper_hash) {
- php_error_docref(NULL, E_NOTICE, "%s:// was never changed, nothing to restore", ZSTR_VAL(protocol));
- RETURN_TRUE;
- }
-
if ((wrapper = zend_hash_find_ptr(global_wrapper_hash, protocol)) == NULL) {
php_error_docref(NULL, E_WARNING, "%s:// never existed, nothing to restore", ZSTR_VAL(protocol));
RETURN_FALSE;
}
+ wrapper_hash = php_stream_get_url_stream_wrappers_hash();
+ if (wrapper_hash == global_wrapper_hash || zend_hash_find_ptr(wrapper_hash, protocol) == wrapper) {
+ php_error_docref(NULL, E_NOTICE, "%s:// was never changed, nothing to restore", ZSTR_VAL(protocol));
+ RETURN_TRUE;
+ }
+
/* A failure here could be okay given that the protocol might have been merely unregistered */
php_unregister_url_stream_wrapper_volatile(protocol);