Skip to content

Add type error on filename which contain null bytes in bzopen #4987

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

Merged
merged 1 commit into from
Dec 8, 2019
Merged
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
3 changes: 2 additions & 1 deletion ext/bz2/bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ static PHP_FUNCTION(bzopen)
}

if (CHECK_ZVAL_NULL_PATH(file)) {
RETURN_FALSE;
zend_type_error("filename must not contain null bytes");
return;
}

stream = php_stream_bz2open(NULL, Z_STRVAL_P(file), mode, REPORT_ERRORS, NULL);
Expand Down
23 changes: 23 additions & 0 deletions ext/bz2/tests/bzopen_string_filename_with_null_bytes.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
bzopen(): throw TypeError if filename contains null bytes
--SKIPIF--
<?php if (!extension_loaded("bz2")) print "skip"; ?>
--FILE--
<?php

try {
bzopen("file\0", "w");
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}

try {
bzopen("file\0", "r");
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECT--
filename must not contain null bytes
filename must not contain null bytes