From: Mark Date: Mon, 26 Aug 2019 21:52:45 +0000 (+0100) Subject: Warnings become errors hash_init X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=14c07fef748126d634a5ef8115cf5f72b8903811;p=php Warnings become errors hash_init --- diff --git a/ext/hash/hash.c b/ext/hash/hash.c index e9cc5bf054..82c27afd64 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -358,19 +358,19 @@ PHP_FUNCTION(hash_init) ops = php_hash_fetch_ops(ZSTR_VAL(algo), ZSTR_LEN(algo)); if (!ops) { - php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); - RETURN_FALSE; + zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); + return; } if (options & PHP_HASH_HMAC) { if (!ops->is_crypto) { - php_error_docref(NULL, E_WARNING, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo)); - RETURN_FALSE; + zend_throw_error(NULL, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo)); + return; } if (!key || (ZSTR_LEN(key) == 0)) { /* Note: a zero length key is no key at all */ - php_error_docref(NULL, E_WARNING, "HMAC requested without a key"); - RETURN_FALSE; + zend_throw_error(NULL, "HMAC requested without a key"); + return; } } diff --git a/ext/hash/tests/hash_init_error.phpt b/ext/hash/tests/hash_init_error.phpt index 9105b96801..a68a8fc088 100644 --- a/ext/hash/tests/hash_init_error.phpt +++ b/ext/hash/tests/hash_init_error.phpt @@ -4,30 +4,48 @@ Hash: hash_init() function - errors test getMessage() . "\n"; +} + +echo "\n-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --\n"; +try { + var_dump(hash_init('crc32', HASH_HMAC)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +echo "\n-- Testing hash_init() function with HASH_HMAC and no key --\n"; +try { + var_dump(hash_init('md5', HASH_HMAC)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(hash_init('md5', HASH_HMAC, null)); +} +catch (\Error $e) { + echo $e->getMessage() . "\n"; +} -echo "-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --\n"; -var_dump(hash_init('crc32', HASH_HMAC)); -echo "-- Testing hash_init() function with HASH_HMAC and no key --\n"; -var_dump(hash_init('md5', HASH_HMAC)); -var_dump(hash_init('md5', HASH_HMAC, null)); ?> ---EXPECTF-- +--EXPECT-- *** Testing hash_init(): error conditions *** + -- Testing hash_init() function with unknown algorithms -- +Unknown hashing algorithm: dummy -Warning: hash_init(): Unknown hashing algorithm: dummy in %s on line %d -bool(false) -- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms -- +HMAC requested with a non-cryptographic hashing algorithm: crc32 -Warning: hash_init(): HMAC requested with a non-cryptographic hashing algorithm: crc32 in %s on line %d -bool(false) -- Testing hash_init() function with HASH_HMAC and no key -- - -Warning: hash_init(): HMAC requested without a key %s on line %d -bool(false) - -Warning: hash_init(): HMAC requested without a key %s on line %d -bool(false) +HMAC requested without a key +HMAC requested without a key