]> granicus.if.org Git - php/commitdiff
Add type error on filename which contain null bytes in bzopen
authorGeorge Peter Banyard <girgias@php.net>
Sun, 8 Dec 2019 14:06:59 +0000 (15:06 +0100)
committerGeorge Peter Banyard <girgias@php.net>
Sun, 8 Dec 2019 14:06:59 +0000 (15:06 +0100)
ext/bz2/bz2.c
ext/bz2/tests/bzopen_string_filename_with_null_bytes.phpt [new file with mode: 0644]

index 98e8bf9770e52e9c5a341c950bc3a149b9a608b6..7b7fb3a2278389d4888b03abb2d535c958e4da46 100644 (file)
@@ -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 (file)
index 0000000..436f87c
--- /dev/null
@@ -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