From 0b3a9376701c3e8095d4fdaa2c363b26df8d20f9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 11 Dec 2021 22:16:00 +0100 Subject: [PATCH] Fix GH-7759: Incorrect return types for hash() and hash_hmac() `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. --- NEWS | 4 ++++ ext/hash/hash.stub.php | 4 ++-- ext/hash/hash_arginfo.h | 13 +++++++++---- ext/opcache/Optimizer/zend_func_info.c | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 18a8b747a0b..020add82e59 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/ext/hash/hash.stub.php b/ext/hash/hash.stub.php index c0d4cbca7c3..250fb68ee4e 100644 --- a/ext/hash/hash.stub.php +++ b/ext/hash/hash.stub.php @@ -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 {} diff --git a/ext/hash/hash_arginfo.h b/ext/hash/hash_arginfo.h index db043da97b4..5aef2c11d1d 100644 --- a/ext/hash/hash_arginfo.h +++ b/ext/hash/hash_arginfo.h @@ -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") @@ -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) diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 3589aa1b3c2..84c9d20966c 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -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),