From c5e0a6aaabe8bdff9538056186c31e93793bb089 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Wed, 4 Sep 2024 16:49:17 -0700 Subject: [PATCH] Fix GH-15752: `finfo_file()` - parameter validation error messages Show the correct parameter names and numbers - the errors are caused by the second parameter being empty or having null bytes, not the first. close GH-15755 --- NEWS | 4 ++++ ext/fileinfo/fileinfo.c | 6 ++++-- ext/fileinfo/tests/finfo_file_001.phpt | 4 ++-- ext/fileinfo/tests/finfo_file_basic.phpt | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index a56df16f5e6..1948d5fe8ba 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,10 @@ PHP NEWS . Fixed bug GH-15551 (Segmentation fault (access null pointer) in ext/dom/xml_common.h). (nielsdos) +- Fileinfo: + . Fixed bug GH-15752 (Incorrect error message for finfo_file + with an empty filename argument). (DanielEScherzer) + - MySQLnd: . Fixed bug GH-15432 (Heap corruption when querying a vector). (cmb, Kamil Tekiela) diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index 8163884577a..63de351106e 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -373,12 +373,14 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime php_stream_wrapper *wrap; php_stream_statbuf ssb; + // Implementation is used for both finfo_file() and mimetype_emu() + int buffer_param_num = (mimetype_emu ? 1 : 2); if (buffer == NULL || buffer_len == 0) { - zend_argument_value_error(1, "cannot be empty"); + zend_argument_value_error(buffer_param_num, "cannot be empty"); goto clean; } if (CHECK_NULL_PATH(buffer, buffer_len)) { - zend_argument_type_error(1, "must not contain any null bytes"); + zend_argument_type_error(buffer_param_num, "must not contain any null bytes"); goto clean; } diff --git a/ext/fileinfo/tests/finfo_file_001.phpt b/ext/fileinfo/tests/finfo_file_001.phpt index 7eb39487b7d..44b0c6beebd 100644 --- a/ext/fileinfo/tests/finfo_file_001.phpt +++ b/ext/fileinfo/tests/finfo_file_001.phpt @@ -21,8 +21,8 @@ var_dump(finfo_file($fp, '&')); ?> --EXPECTF-- -finfo_file(): Argument #1 ($finfo) must not contain any null bytes -finfo_file(): Argument #1 ($finfo) cannot be empty +finfo_file(): Argument #2 ($filename) must not contain any null bytes +finfo_file(): Argument #2 ($filename) cannot be empty string(9) "directory" Warning: finfo_file(&): Failed to open stream: No such file or directory in %s on line %d diff --git a/ext/fileinfo/tests/finfo_file_basic.phpt b/ext/fileinfo/tests/finfo_file_basic.phpt index 0d4cca05c83..b2c3957fa3c 100644 --- a/ext/fileinfo/tests/finfo_file_basic.phpt +++ b/ext/fileinfo/tests/finfo_file_basic.phpt @@ -25,4 +25,4 @@ try { string(28) "text/x-php; charset=us-ascii" string(22) "PHP script, ASCII text" string(28) "text/plain; charset=us-ascii" -finfo_file(): Argument #1 ($finfo) must not contain any null bytes +finfo_file(): Argument #2 ($filename) must not contain any null bytes