From f3e920f4826be37878aa77b93900ac35bbf11a3f Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 22 Sep 2020 14:46:22 +0200 Subject: [PATCH 1/2] Fix #76735: Incorrect message in fopen on invalid mode We have to log errors in `stream_opener` callbacks to the wrapper's error log, because otherwise we may pick up an unrelated `errno` or a most generic message. --- ext/standard/tests/file/bug76735.phpt | 8 ++++++++ main/streams/plain_wrapper.c | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 ext/standard/tests/file/bug76735.phpt diff --git a/ext/standard/tests/file/bug76735.phpt b/ext/standard/tests/file/bug76735.phpt new file mode 100644 index 0000000000000..451988cc65542 --- /dev/null +++ b/ext/standard/tests/file/bug76735.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #76735 (Incorrect message in fopen on invalid mode) +--FILE-- + +--EXPECTF-- +Warning: fopen(%s): failed to open stream: `Q' is not a valid mode for fopen in %s on line %d diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index d00a6efe29d28..131f77c4218eb 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1021,9 +1021,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen char *persistent_id = NULL; if (FAILURE == php_stream_parse_fopen_modes(mode, &open_flags)) { - if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "`%s' is not a valid mode for fopen", mode); - } + php_stream_wrapper_log_error(&php_plain_files_wrapper, options, "`%s' is not a valid mode for fopen", mode); return NULL; } From 62b52e50eb3d74098f888dee67cac53e8a13b7fe Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 22 Sep 2020 18:57:21 +0200 Subject: [PATCH 2/2] Fix bz2 test --- ext/bz2/tests/002.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/bz2/tests/002.phpt b/ext/bz2/tests/002.phpt index a69514a71132c..1b0fd2a660742 100644 --- a/ext/bz2/tests/002.phpt +++ b/ext/bz2/tests/002.phpt @@ -83,12 +83,12 @@ bool(false) resource(%d) of type (stream) resource(%d) of type (stream) -Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d +Warning: fopen(bz_open_002.txt): failed to open stream: `br' is not a valid mode for fopen in %s on line %d Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d bool(false) -Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d +Warning: fopen(bz_open_002.txt): failed to open stream: `br' is not a valid mode for fopen in %s on line %d Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d bool(false)