mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
Promote warnings to exceptions in ext/hash
This commit is contained in:
parent
a42e8e8ec4
commit
d5871e26ad
3 changed files with 20 additions and 16 deletions
|
@ -132,13 +132,13 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_
|
||||||
|
|
||||||
ops = php_hash_fetch_ops(algo);
|
ops = php_hash_fetch_ops(algo);
|
||||||
if (!ops) {
|
if (!ops) {
|
||||||
php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
|
zend_argument_value_error(1, "must be a valid hashing algorithm");
|
||||||
RETURN_FALSE;
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
if (isfilename) {
|
if (isfilename) {
|
||||||
if (CHECK_NULL_PATH(data, data_len)) {
|
if (CHECK_NULL_PATH(data, data_len)) {
|
||||||
php_error_docref(NULL, E_WARNING, "Invalid path");
|
zend_argument_value_error(1, "must be a valid path");
|
||||||
RETURN_FALSE;
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context));
|
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context));
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
|
@ -1065,8 +1065,8 @@ PHP_FUNCTION(mhash_keygen_s2k)
|
||||||
|
|
||||||
bytes = (int)l_bytes;
|
bytes = (int)l_bytes;
|
||||||
if (bytes <= 0){
|
if (bytes <= 0){
|
||||||
php_error_docref(NULL, E_WARNING, "The byte parameter must be greater than 0");
|
zend_argument_value_error(4, "must be a greater than 0");
|
||||||
RETURN_FALSE;
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
||||||
salt_len = MIN(salt_len, SALT_SIZE);
|
salt_len = MIN(salt_len, SALT_SIZE);
|
||||||
|
|
|
@ -11,13 +11,15 @@ Hash: hash() function : error conditions
|
||||||
echo "*** Testing hash() : error conditions ***\n";
|
echo "*** Testing hash() : error conditions ***\n";
|
||||||
|
|
||||||
echo "\n-- Testing hash() function with invalid hash algorithm --\n";
|
echo "\n-- Testing hash() function with invalid hash algorithm --\n";
|
||||||
var_dump(hash('foo', ''));
|
try {
|
||||||
|
hash('foo', '');
|
||||||
|
} catch (ValueError $exception) {
|
||||||
|
echo $exception->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECT--
|
||||||
*** Testing hash() : error conditions ***
|
*** Testing hash() : error conditions ***
|
||||||
|
|
||||||
-- Testing hash() function with invalid hash algorithm --
|
-- Testing hash() function with invalid hash algorithm --
|
||||||
|
hash(): Argument #1 ($algo) must be a valid hashing algorithm
|
||||||
Warning: hash(): Unknown hashing algorithm: foo in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
|
|
|
@ -19,10 +19,14 @@ file_put_contents( $filename, 'The quick brown fox jumped over the lazy dog.' );
|
||||||
|
|
||||||
// hash_file() error tests
|
// hash_file() error tests
|
||||||
echo "\n-- Testing hash_file() function with an unknown algorithm --\n";
|
echo "\n-- Testing hash_file() function with an unknown algorithm --\n";
|
||||||
var_dump( hash_file( 'foobar', $filename ) );
|
try {
|
||||||
|
hash_file('foobar', $filename);
|
||||||
|
} catch (ValueError $exception) {
|
||||||
|
echo $exception->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
echo "\n-- Testing hash_file() function with a non-existent file --\n";
|
echo "\n-- Testing hash_file() function with a non-existent file --\n";
|
||||||
var_dump( hash_file( 'md5', 'nonexistent.txt' ) );
|
var_dump(hash_file('md5', 'nonexistent.txt'));
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--CLEAN--
|
--CLEAN--
|
||||||
|
@ -36,9 +40,7 @@ unlink( $filename );
|
||||||
*** Testing hash_file() : error conditions ***
|
*** Testing hash_file() : error conditions ***
|
||||||
|
|
||||||
-- Testing hash_file() function with an unknown algorithm --
|
-- Testing hash_file() function with an unknown algorithm --
|
||||||
|
hash_file(): Argument #1 ($algo) must be a valid hashing algorithm
|
||||||
Warning: hash_file(): Unknown hashing algorithm: %s in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
|
|
||||||
-- Testing hash_file() function with a non-existent file --
|
-- Testing hash_file() function with a non-existent file --
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue