Skip to content

Commit 056cfe7

Browse files
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.
1 parent 6cab769 commit 056cfe7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

ext/fileinfo/fileinfo.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,14 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
373373
php_stream_wrapper *wrap;
374374
php_stream_statbuf ssb;
375375

376+
// Implementation is used for both finfo_file() and mimetype_emu()
377+
int buffer_param_num = (mimetype_emu ? 1 : 2);
376378
if (buffer == NULL || buffer_len == 0) {
377-
zend_argument_value_error(1, "cannot be empty");
379+
zend_argument_value_error(buffer_param_num, "cannot be empty");
378380
goto clean;
379381
}
380382
if (CHECK_NULL_PATH(buffer, buffer_len)) {
381-
zend_argument_type_error(1, "must not contain any null bytes");
383+
zend_argument_type_error(buffer_param_num, "must not contain any null bytes");
382384
goto clean;
383385
}
384386

ext/fileinfo/tests/finfo_file_001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var_dump(finfo_file($fp, '&'));
2121

2222
?>
2323
--EXPECTF--
24-
finfo_file(): Argument #1 ($finfo) must not contain any null bytes
25-
finfo_file(): Argument #1 ($finfo) cannot be empty
24+
finfo_file(): Argument #2 ($filename) must not contain any null bytes
25+
finfo_file(): Argument #2 ($filename) cannot be empty
2626
string(9) "directory"
2727

2828
Warning: finfo_file(&): Failed to open stream: No such file or directory in %s on line %d

0 commit comments

Comments
 (0)