]> granicus.if.org Git - php/commitdiff
Make url_stats in resolve_path quiet
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Dec 2019 22:06:12 +0000 (23:06 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Dec 2019 22:22:26 +0000 (23:22 +0100)
These stats are used to check whether the file exists -- they
should not generate errors. Having the flag set is particularly
important for custom stream wrappers.

Zend/tests/include_stat_is_quiet.phpt [new file with mode: 0644]
main/fopen_wrappers.c

diff --git a/Zend/tests/include_stat_is_quiet.phpt b/Zend/tests/include_stat_is_quiet.phpt
new file mode 100644 (file)
index 0000000..006fad5
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Stats executed during include path resolution should be silent
+--FILE--
+<?php
+
+class StreamWrapper {
+    public function url_stat($path, $flags) {
+        $path = str_replace('test://', 'file://', $path);
+        if ($flags & STREAM_URL_STAT_QUIET) {
+            return @stat($path);
+        } else {
+            return stat($path);
+        }
+    }
+}
+
+stream_wrapper_register('test', StreamWrapper::class);
+set_include_path('test://foo:test://bar');
+
+try {
+    require_once 'doesnt_exist.php';
+} catch (Exception $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECTF--
+Warning: require_once(doesnt_exist.php): failed to open stream: No such file or directory in %s on line %d
+
+Fatal error: require_once(): Failed opening required 'doesnt_exist.php' (include_path='test://foo:test://bar') in %s on line %d
index c85e0af7abc6c96828bf488f05815b71ccba1c7a..11d31366d72026a2e69943b1f35d3239c200f04a 100644 (file)
@@ -558,7 +558,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
                                if (wrapper->wops->url_stat) {
                                        php_stream_statbuf ssb;
 
-                                       if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
+                                       if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL)) {
                                                return zend_string_init(trypath, strlen(trypath), 0);
                                        }
                                        if (EG(exception)) {
@@ -598,7 +598,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
                                        if (wrapper->wops->url_stat) {
                                                php_stream_statbuf ssb;
 
-                                               if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
+                                               if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL)) {
                                                        return zend_string_init(trypath, strlen(trypath), 0);
                                                }
                                                if (EG(exception)) {