summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-12-30 23:06:12 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-12-30 23:22:26 +0100
commit003be875e4dda029a358fb2d1da44a0b5ff86c6a (patch)
tree0f5d569b76bcbb28acc0b0107944be17bae890b0
parent98df5c97f47dd3a50cb43763a1811f86f2ca912e (diff)
downloadphp-git-003be875e4dda029a358fb2d1da44a0b5ff86c6a.tar.gz
Make url_stats in resolve_path quiet
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.
-rw-r--r--Zend/tests/include_stat_is_quiet.phpt30
-rw-r--r--main/fopen_wrappers.c4
2 files changed, 32 insertions, 2 deletions
diff --git a/Zend/tests/include_stat_is_quiet.phpt b/Zend/tests/include_stat_is_quiet.phpt
new file mode 100644
index 0000000000..006fad50bd
--- /dev/null
+++ b/Zend/tests/include_stat_is_quiet.phpt
@@ -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
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index c85e0af7ab..11d31366d7 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -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)) {