Skip to content

Fix GH-15752: finfo_file() - parameter validation error messages #15755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/fileinfo/tests/finfo_file_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/fileinfo/tests/finfo_file_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading