Promote empty filename to ValueError in BZ2 extension

This commit is contained in:
George Peter Banyard 2020-07-31 14:01:05 +01:00
parent c3105a1f8d
commit 4095c0a28d
2 changed files with 20 additions and 19 deletions

View file

@ -350,7 +350,7 @@ PHP_FUNCTION(bzopen)
/* If it's not a resource its a string containing the filename to open */ /* If it's not a resource its a string containing the filename to open */
if (Z_TYPE_P(file) == IS_STRING) { if (Z_TYPE_P(file) == IS_STRING) {
if (Z_STRLEN_P(file) == 0) { if (Z_STRLEN_P(file) == 0) {
php_error_docref(NULL, E_WARNING, "Filename cannot be empty"); zend_argument_value_error(1, "cannot be empty");
RETURN_FALSE; RETURN_FALSE;
} }

View file

@ -6,44 +6,45 @@ bzopen() and invalid parameters
<?php <?php
try { try {
var_dump(bzopen("", "")); var_dump(bzopen("", "r"));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
var_dump(bzopen("", "r"));
var_dump(bzopen("", "w"));
try {
var_dump(bzopen("", "x"));
} catch (\ValueError $e) { } catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL; echo $e->getMessage() . \PHP_EOL;
} }
try { try {
var_dump(bzopen("", "rw")); var_dump(bzopen("", "w"));
} catch (\ValueError $e) { } catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL; echo $e->getMessage() . \PHP_EOL;
} }
try { try {
var_dump(bzopen("no_such_file", "r")); var_dump(bzopen("no_such_file", ""));
} catch (\ValueError $e) { } catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL; echo $e->getMessage() . \PHP_EOL;
} }
try {
var_dump(bzopen("no_such_file", "x"));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(bzopen("no_such_file", "rw"));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
var_dump(bzopen("no_such_file", "r"));
$fp = fopen(__FILE__,"r"); $fp = fopen(__FILE__,"r");
var_dump(bzopen($fp, "r")); var_dump(bzopen($fp, "r"));
?> ?>
--EXPECTF-- --EXPECTF--
bzopen(): Argument #1 ($file) cannot be empty
bzopen(): Argument #1 ($file) cannot be empty
bzopen(): Argument #2 ($mode) must be either "r" or "w" bzopen(): Argument #2 ($mode) must be either "r" or "w"
Warning: bzopen(): Filename cannot be empty in %s on line %d
bool(false)
Warning: bzopen(): Filename cannot be empty in %s on line %d
bool(false)
bzopen(): Argument #2 ($mode) must be either "r" or "w" bzopen(): Argument #2 ($mode) must be either "r" or "w"
bzopen(): Argument #2 ($mode) must be either "r" or "w" bzopen(): Argument #2 ($mode) must be either "r" or "w"