diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index 98e8bf9770e5..7b7fb3a22783 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -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); diff --git a/ext/bz2/tests/bzopen_string_filename_with_null_bytes.phpt b/ext/bz2/tests/bzopen_string_filename_with_null_bytes.phpt new file mode 100644 index 000000000000..436f87cab40b --- /dev/null +++ b/ext/bz2/tests/bzopen_string_filename_with_null_bytes.phpt @@ -0,0 +1,23 @@ +--TEST-- +bzopen(): throw TypeError if filename contains null bytes +--SKIPIF-- + +--FILE-- +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