Skip to content

Commit 14c07fe

Browse files
marandallkrakjoe
authored andcommitted
Warnings become errors hash_init
1 parent 2158785 commit 14c07fe

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

ext/hash/hash.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,19 +358,19 @@ PHP_FUNCTION(hash_init)
358358

359359
ops = php_hash_fetch_ops(ZSTR_VAL(algo), ZSTR_LEN(algo));
360360
if (!ops) {
361-
php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
362-
RETURN_FALSE;
361+
zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
362+
return;
363363
}
364364

365365
if (options & PHP_HASH_HMAC) {
366366
if (!ops->is_crypto) {
367-
php_error_docref(NULL, E_WARNING, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo));
368-
RETURN_FALSE;
367+
zend_throw_error(NULL, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo));
368+
return;
369369
}
370370
if (!key || (ZSTR_LEN(key) == 0)) {
371371
/* Note: a zero length key is no key at all */
372-
php_error_docref(NULL, E_WARNING, "HMAC requested without a key");
373-
RETURN_FALSE;
372+
zend_throw_error(NULL, "HMAC requested without a key");
373+
return;
374374
}
375375
}
376376

ext/hash/tests/hash_init_error.phpt

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,48 @@ Hash: hash_init() function - errors test
44
<?php
55
echo "*** Testing hash_init(): error conditions ***\n";
66

7-
echo "-- Testing hash_init() function with unknown algorithms --\n";
8-
var_dump(hash_init('dummy'));
7+
echo "\n-- Testing hash_init() function with unknown algorithms --\n";
8+
try {
9+
var_dump(hash_init('dummy'));
10+
}
11+
catch (\Error $e) {
12+
echo $e->getMessage() . "\n";
13+
}
14+
15+
echo "\n-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --\n";
16+
try {
17+
var_dump(hash_init('crc32', HASH_HMAC));
18+
}
19+
catch (\Error $e) {
20+
echo $e->getMessage() . "\n";
21+
}
22+
23+
echo "\n-- Testing hash_init() function with HASH_HMAC and no key --\n";
24+
try {
25+
var_dump(hash_init('md5', HASH_HMAC));
26+
}
27+
catch (\Error $e) {
28+
echo $e->getMessage() . "\n";
29+
}
30+
31+
try {
32+
var_dump(hash_init('md5', HASH_HMAC, null));
33+
}
34+
catch (\Error $e) {
35+
echo $e->getMessage() . "\n";
36+
}
937

10-
echo "-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --\n";
11-
var_dump(hash_init('crc32', HASH_HMAC));
1238

13-
echo "-- Testing hash_init() function with HASH_HMAC and no key --\n";
14-
var_dump(hash_init('md5', HASH_HMAC));
15-
var_dump(hash_init('md5', HASH_HMAC, null));
1639
?>
17-
--EXPECTF--
40+
--EXPECT--
1841
*** Testing hash_init(): error conditions ***
42+
1943
-- Testing hash_init() function with unknown algorithms --
44+
Unknown hashing algorithm: dummy
2045

21-
Warning: hash_init(): Unknown hashing algorithm: dummy in %s on line %d
22-
bool(false)
2346
-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --
47+
HMAC requested with a non-cryptographic hashing algorithm: crc32
2448

25-
Warning: hash_init(): HMAC requested with a non-cryptographic hashing algorithm: crc32 in %s on line %d
26-
bool(false)
2749
-- Testing hash_init() function with HASH_HMAC and no key --
28-
29-
Warning: hash_init(): HMAC requested without a key %s on line %d
30-
bool(false)
31-
32-
Warning: hash_init(): HMAC requested without a key %s on line %d
33-
bool(false)
50+
HMAC requested without a key
51+
HMAC requested without a key

0 commit comments

Comments
 (0)