Skip to content

Commit

Permalink
Fix GH-7759: Incorrect return types for hash() and hash_hmac()
Browse files Browse the repository at this point in the history
`hash()` and `hash_hmac()` never return `false`; only `hash_file()` and
`hash_hmac_file()` return `false` in case the data cannot be read.

Closes GH-7760.
  • Loading branch information
cmb69 committed Dec 12, 2021
1 parent 778513f commit 0b3a937
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ PHP NEWS
. Fixed bug #81585 (cached_chunks are not counted to real_size on shutdown).
(cmb)

- Hash:
. Fixed bug GH-7759 (Incorrect return types for hash() and hash_hmac()).
(cmb)

- PDO_PGSQL:
. Fixed error message allocation of PDO PgSQL. (SATO Kentaro)

Expand Down
4 changes: 2 additions & 2 deletions ext/hash/hash.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

/** @generate-function-entries */

function hash(string $algo, string $data, bool $binary = false): string|false {}
function hash(string $algo, string $data, bool $binary = false): string {}

function hash_file(string $algo, string $filename, bool $binary = false): string|false {}

function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string|false {}
function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string {}

function hash_hmac_file(string $algo, string $data, string $key, bool $binary = false): string|false {}

Expand Down
13 changes: 9 additions & 4 deletions ext/hash/hash_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 9352e0ac98e2ac53dc15d5024f9ef0c8092c4e9c */
* Stub hash: f73c6fa1a4ac1ca93f87775bbe69fbdb2deb5746 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
Expand All @@ -13,14 +13,19 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_file, 0, 2, MAY_BE_STRING|M
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_hmac, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash_hmac, 0, 3, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
ZEND_END_ARG_INFO()

#define arginfo_hash_hmac_file arginfo_hash_hmac
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_hmac_file, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_hash_init, 0, 1, HashContext, 0)
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/Optimizer/zend_func_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ static const func_info_t func_infos[] = {
F1("ob_gzhandler", MAY_BE_FALSE | MAY_BE_STRING),

/* ext/hash */
F1("hash", MAY_BE_FALSE | MAY_BE_STRING),
F1("hash", MAY_BE_STRING),
F1("hash_file", MAY_BE_FALSE | MAY_BE_STRING),
F1("hash_hmac", MAY_BE_FALSE | MAY_BE_STRING),
F1("hash_hmac", MAY_BE_STRING),
F1("hash_hmac_algos", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
F1("hash_hmac_file", MAY_BE_FALSE | MAY_BE_STRING),
F1("hash_hkdf", MAY_BE_STRING),
Expand Down

0 comments on commit 0b3a937

Please sign in to comment.