From 2741476838b49055449ea1ba2e128920608910b0 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 8 Dec 2019 15:06:59 +0100 Subject: [PATCH] Add type error on filename which contain null bytes in bzopen --- ext/bz2/bz2.c | 3 ++- ...zopen_string_filename_with_null_bytes.phpt | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 ext/bz2/tests/bzopen_string_filename_with_null_bytes.phpt 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