Skip to content

Commit 2158785

Browse files
marandallkrakjoe
authored andcommitted
Warnings become errors hash_hmac hash_hmac_file
1 parent 62751b0 commit 2158785

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

ext/hash/hash.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,18 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename,
252252

253253
ops = php_hash_fetch_ops(algo, algo_len);
254254
if (!ops) {
255-
php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo);
256-
RETURN_FALSE;
255+
zend_throw_error(NULL, "Unknown hashing algorithm: %s", algo);
256+
return;
257257
}
258258
else if (!ops->is_crypto) {
259-
php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", algo);
260-
RETURN_FALSE;
259+
zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", algo);
260+
return;
261261
}
262262

263263
if (isfilename) {
264264
if (CHECK_NULL_PATH(data, data_len)) {
265-
php_error_docref(NULL, E_WARNING, "Invalid path");
266-
RETURN_FALSE;
265+
zend_throw_error(NULL, "Invalid path");
266+
return;
267267
}
268268
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context));
269269
if (!stream) {

ext/hash/tests/hash_hmac_error.phpt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,29 @@ $data = "This is a sample string used to test the hash_hmac function with variou
1313
$key = 'secret';
1414

1515
echo "\n-- Testing hash_hmac() function with invalid hash algorithm --\n";
16-
var_dump(hash_hmac('foo', $data, $key));
16+
try {
17+
var_dump(hash_hmac('foo', $data, $key));
18+
}
19+
catch (\Error $e) {
20+
echo $e->getMessage() . "\n";
21+
}
1722

1823
echo "\n-- Testing hash_hmac() function with non-cryptographic hash algorithm --\n";
19-
var_dump(hash_hmac('crc32', $data, $key));
24+
try {
25+
var_dump(hash_hmac('crc32', $data, $key));
26+
}
27+
catch (\Error $e) {
28+
echo $e->getMessage() . "\n";
29+
}
2030

2131
?>
2232
===Done===
23-
--EXPECTF--
33+
--EXPECT--
2434
*** Testing hash_hmac() : error conditions ***
2535

2636
-- Testing hash_hmac() function with invalid hash algorithm --
27-
28-
Warning: hash_hmac(): Unknown hashing algorithm: foo in %s on line %d
29-
bool(false)
37+
Unknown hashing algorithm: foo
3038

3139
-- Testing hash_hmac() function with non-cryptographic hash algorithm --
32-
33-
Warning: hash_hmac(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
34-
bool(false)
40+
Non-cryptographic hashing algorithm: crc32
3541
===Done===

ext/hash/tests/hash_hmac_file_error.phpt

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,40 @@ $file = __DIR__ . "hash_file.txt";
1515
$key = 'secret';
1616

1717
echo "\n-- Testing hash_hmac_file() function with invalid hash algorithm --\n";
18-
hash_hmac_file('foo', $file, $key, TRUE);
18+
try {
19+
var_dump(hash_hmac_file('foo', $file, $key, TRUE));
20+
}
21+
catch (\Error $e) {
22+
echo $e->getMessage() . "\n";
23+
}
1924

2025
echo "\n-- Testing hash_hmac_file() function with non-cryptographic hash algorithm --\n";
21-
hash_hmac_file('crc32', $file, $key, TRUE);
26+
try {
27+
var_dump(hash_hmac_file('crc32', $file, $key, TRUE));
28+
}
29+
catch (\Error $e) {
30+
echo $e->getMessage() . "\n";
31+
}
2232

2333
echo "\n-- Testing hash_hmac_file() function with bad path --\n";
24-
hash_hmac_file('md5', $file.chr(0).$file, $key, TRUE);
34+
try {
35+
var_dump(hash_hmac_file('md5', $file.chr(0).$file, $key, TRUE));
36+
}
37+
catch (\Error $e) {
38+
echo $e->getMessage() . "\n";
39+
}
2540

2641
?>
2742
===Done===
28-
--EXPECTF--
43+
--EXPECT--
2944
*** Testing hash() : error conditions ***
3045

3146
-- Testing hash_hmac_file() function with invalid hash algorithm --
32-
33-
Warning: hash_hmac_file(): Unknown hashing algorithm: foo in %s on line %d
47+
Unknown hashing algorithm: foo
3448

3549
-- Testing hash_hmac_file() function with non-cryptographic hash algorithm --
36-
37-
Warning: hash_hmac_file(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
50+
Non-cryptographic hashing algorithm: crc32
3851

3952
-- Testing hash_hmac_file() function with bad path --
40-
41-
Warning: hash_hmac_file(): Invalid path in %s on line %d
53+
Invalid path
4254
===Done===

0 commit comments

Comments
 (0)