com php-src: Warnings become errors hash_hmac hash_hmac _file: ext/hash/hash.c ext/hash/tests/hash_hmac_e rror.phpt
ext/hash/tests/hash_hmac_file_error.phpt

From: Date: Thu, 29 Aug 2019 14:08:16 +0000
Subject: com php-src: Warnings become errors hash_hmac hash_hmac _file: ext/hash/hash.c ext/hash/tests/hash_hmac_e rror.phpt
ext/hash/tests/hash_hmac_file_error.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-108133@lists.php.net to get a copy of this message
Commit: 21587854b437db14db7e4d601421d2c7702afe4f Author: Mark <mrandall@digitellinc.com> Mon, 26 Aug 2019 22:34:50 +0100 Committer: Joe Watkins <krakjoe@php.net> Thu, 29 Aug 2019 16:08:16 +0200 Parents: 62751b0d453ac51c559ea31d360a290081eb0c1d Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=21587854b437db14db7e4d601421d2c7702afe4f Log: Warnings become errors hash_hmac hash_hmac_file Changed paths: M ext/hash/hash.c M ext/hash/tests/hash_hmac_error.phpt M ext/hash/tests/hash_hmac_file_error.phpt Diff: diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 2fbff0d..e9cc5bf 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -252,18 +252,18 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, 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 (isfilename) { if (CHECK_NULL_PATH(data, data_len)) { - php_error_docref(NULL, E_WARNING, "Invalid path"); - RETURN_FALSE; + zend_throw_error(NULL, "Invalid path"); + return; } stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); if (!stream) { diff --git a/ext/hash/tests/hash_hmac_error.phpt b/ext/hash/tests/hash_hmac_error.phpt index 1ed3e54..fe9ed73 100644 --- a/ext/hash/tests/hash_hmac_error.phpt +++ b/ext/hash/tests/hash_hmac_error.phpt @@ -13,23 +13,29 @@ $data = "This is a sample string used to test the hash_hmac function with variou $key = 'secret'; echo "\n-- Testing hash_hmac() function with invalid hash algorithm --\n"; -var_dump(hash_hmac('foo', $data, $key)); +try { + var_dump(hash_hmac('foo', $data, $key)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing hash_hmac() function with non-cryptographic hash algorithm --\n"; -var_dump(hash_hmac('crc32', $data, $key)); +try { + var_dump(hash_hmac('crc32', $data, $key)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} ?> ===Done=== ---EXPECTF-- +--EXPECT-- *** Testing hash_hmac() : error conditions *** -- Testing hash_hmac() function with invalid hash algorithm -- - -Warning: hash_hmac(): Unknown hashing algorithm: foo in %s on line %d -bool(false) +Unknown hashing algorithm: foo -- Testing hash_hmac() function with non-cryptographic hash algorithm -- - -Warning: hash_hmac(): Non-cryptographic hashing algorithm: crc32 in %s on line %d -bool(false) +Non-cryptographic hashing algorithm: crc32 ===Done=== diff --git a/ext/hash/tests/hash_hmac_file_error.phpt b/ext/hash/tests/hash_hmac_file_error.phpt index 67a4a85..5660b0f 100644 --- a/ext/hash/tests/hash_hmac_file_error.phpt +++ b/ext/hash/tests/hash_hmac_file_error.phpt @@ -15,28 +15,40 @@ $file = __DIR__ . "hash_file.txt"; $key = 'secret'; echo "\n-- Testing hash_hmac_file() function with invalid hash algorithm --\n"; -hash_hmac_file('foo', $file, $key, TRUE); +try { + var_dump(hash_hmac_file('foo', $file, $key, TRUE)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing hash_hmac_file() function with non-cryptographic hash algorithm --\n"; -hash_hmac_file('crc32', $file, $key, TRUE); +try { + var_dump(hash_hmac_file('crc32', $file, $key, TRUE)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing hash_hmac_file() function with bad path --\n"; -hash_hmac_file('md5', $file.chr(0).$file, $key, TRUE); +try { + var_dump(hash_hmac_file('md5', $file.chr(0).$file, $key, TRUE)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} ?> ===Done=== ---EXPECTF-- +--EXPECT-- *** Testing hash() : error conditions *** -- Testing hash_hmac_file() function with invalid hash algorithm -- - -Warning: hash_hmac_file(): Unknown hashing algorithm: foo in %s on line %d +Unknown hashing algorithm: foo -- Testing hash_hmac_file() function with non-cryptographic hash algorithm -- - -Warning: hash_hmac_file(): Non-cryptographic hashing algorithm: crc32 in %s on line %d +Non-cryptographic hashing algorithm: crc32 -- Testing hash_hmac_file() function with bad path -- - -Warning: hash_hmac_file(): Invalid path in %s on line %d +Invalid path ===Done===

« previous php.cvs (#108133) next »