Skip to content

Commit 2741476

Browse files
committed
Add type error on filename which contain null bytes in bzopen
1 parent 2ede8db commit 2741476

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

ext/bz2/bz2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ static PHP_FUNCTION(bzopen)
379379
}
380380

381381
if (CHECK_ZVAL_NULL_PATH(file)) {
382-
RETURN_FALSE;
382+
zend_type_error("filename must not contain null bytes");
383+
return;
383384
}
384385

385386
stream = php_stream_bz2open(NULL, Z_STRVAL_P(file), mode, REPORT_ERRORS, NULL);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
bzopen(): throw TypeError if filename contains null bytes
3+
--SKIPIF--
4+
<?php if (!extension_loaded("bz2")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
try {
9+
bzopen("file\0", "w");
10+
} catch (\TypeError $e) {
11+
echo $e->getMessage() . \PHP_EOL;
12+
}
13+
14+
try {
15+
bzopen("file\0", "r");
16+
} catch (\TypeError $e) {
17+
echo $e->getMessage() . \PHP_EOL;
18+
}
19+
20+
?>
21+
--EXPECT--
22+
filename must not contain null bytes
23+
filename must not contain null bytes

0 commit comments

Comments
 (0)