]> granicus.if.org Git - php/commitdiff
Warnings become errors hash_init
authorMark <mrandall@digitellinc.com>
Mon, 26 Aug 2019 21:52:45 +0000 (22:52 +0100)
committerJoe Watkins <krakjoe@php.net>
Thu, 29 Aug 2019 14:09:29 +0000 (16:09 +0200)
ext/hash/hash.c
ext/hash/tests/hash_init_error.phpt

index e9cc5bf054c386b8c79ad6258a7a24d4f8567c0e..82c27afd6421af3630cf1c48a4575e0bc5c0e757 100644 (file)
@@ -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;
                }
        }
 
index 9105b96801ad19cd68fc8ade1647afdd8daf3af0..a68a8fc088d0ca19715a8f256bb1fdf197179a88 100644 (file)
@@ -4,30 +4,48 @@ Hash: hash_init() function - errors test
 <?php
 echo "*** Testing hash_init(): error conditions ***\n";
 
-echo "-- Testing hash_init() function with unknown algorithms --\n";
-var_dump(hash_init('dummy'));
+echo "\n-- Testing hash_init() function with unknown algorithms --\n";
+try {
+    var_dump(hash_init('dummy'));
+}
+catch (\Error $e) {
+    echo $e->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