com php-src: Errorfy hash_pbkdf2: ext/hash/hash.c e xt/hash/tests/hash_pbkdf2_error.phpt

From: Date: Thu, 29 Aug 2019 14:11:21 +0000
Subject: com php-src: Errorfy hash_pbkdf2: ext/hash/hash.c e xt/hash/tests/hash_pbkdf2_error.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-108137@lists.php.net to get a copy of this message
Commit: e18bac96b70d37ccfdead11b7c465a75401c58bb Author: Mark <mrandall@digitellinc.com> Mon, 26 Aug 2019 23:31:28 +0100 Committer: Joe Watkins <krakjoe@php.net> Thu, 29 Aug 2019 16:11:21 +0200 Parents: ee104cf1bb9cb7c269459b94248d416e270cbf8e Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e18bac96b70d37ccfdead11b7c465a75401c58bb Log: Errorfy hash_pbkdf2 Changed paths: M ext/hash/hash.c M ext/hash/tests/hash_pbkdf2_error.phpt Diff: diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 5ec0655..8a9485c 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -739,27 +739,27 @@ PHP_FUNCTION(hash_pbkdf2) ops = php_hash_fetch_ops(algo, algo_len); if (!ops) { - php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo); - RETURN_FALSE; + zend_throw_error(NULL, "Unknown hashing algorithm: %s", algo); + return; } else if (!ops->is_crypto) { - php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", algo); - RETURN_FALSE; + zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", algo); + return; } if (iterations <= 0) { - php_error_docref(NULL, E_WARNING, "Iterations must be a positive integer: " ZEND_LONG_FMT, iterations); - RETURN_FALSE; + zend_throw_error(NULL, "Iterations must be a positive integer: " ZEND_LONG_FMT, iterations); + return; } if (length < 0) { - php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length); - RETURN_FALSE; + zend_throw_error(NULL, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length); + return; } if (salt_len > INT_MAX - 4) { - php_error_docref(NULL, E_WARNING, "Supplied salt is too long, max of INT_MAX - 4 bytes: %zd supplied", salt_len); - RETURN_FALSE; + zend_throw_error(NULL, "Supplied salt is too long, max of INT_MAX - 4 bytes: %zd supplied", salt_len); + return; } context = emalloc(ops->context_size); diff --git a/ext/hash/tests/hash_pbkdf2_error.phpt b/ext/hash/tests/hash_pbkdf2_error.phpt index a7fd086..4cb5ede 100644 --- a/ext/hash/tests/hash_pbkdf2_error.phpt +++ b/ext/hash/tests/hash_pbkdf2_error.phpt @@ -13,43 +13,60 @@ $password = 'password'; $salt = 'salt'; echo "\n-- Testing hash_pbkdf2() function with invalid hash algorithm --\n"; -var_dump(hash_pbkdf2('foo', $password, $salt, 1)); +try { + var_dump(hash_pbkdf2('foo', $password, $salt, 1)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + echo "\n-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --\n"; -var_dump(hash_pbkdf2('crc32', $password, $salt, 1)); +try { + var_dump(hash_pbkdf2('crc32', $password, $salt, 1)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing hash_pbkdf2() function with invalid iterations --\n"; -var_dump(hash_pbkdf2('md5', $password, $salt, 0)); -var_dump(hash_pbkdf2('md5', $password, $salt, -1)); +try { + var_dump(hash_pbkdf2('md5', $password, $salt, 0)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(hash_pbkdf2('md5', $password, $salt, -1)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing hash_pbkdf2() function with invalid length --\n"; -var_dump(hash_pbkdf2('md5', $password, $salt, 1, -1)); +try { + var_dump(hash_pbkdf2('md5', $password, $salt, 1, -1)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} ?> ===Done=== ---EXPECTF-- +--EXPECT-- *** Testing hash_pbkdf2() : error conditions *** -- Testing hash_pbkdf2() function with invalid hash algorithm -- - -Warning: hash_pbkdf2(): Unknown hashing algorithm: foo in %s on line %d -bool(false) +Unknown hashing algorithm: foo -- Testing hash_pbkdf2() function with non-cryptographic hash algorithm -- - -Warning: hash_pbkdf2(): Non-cryptographic hashing algorithm: crc32 in %s on line %d -bool(false) +Non-cryptographic hashing algorithm: crc32 -- Testing hash_pbkdf2() function with invalid iterations -- - -Warning: hash_pbkdf2(): Iterations must be a positive integer: 0 in %s on line %d -bool(false) - -Warning: hash_pbkdf2(): Iterations must be a positive integer: -1 in %s on line %d -bool(false) +Iterations must be a positive integer: 0 +Iterations must be a positive integer: -1 -- Testing hash_pbkdf2() function with invalid length -- - -Warning: hash_pbkdf2(): Length must be greater than or equal to 0: -1 in %s on line %d -bool(false) +Length must be greater than or equal to 0: -1 ===Done===

« previous php.cvs (#108137) next »