From d8ef868b92b9c7ae811639d8c6cc9b58aa402a98 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Sun, 26 Nov 2023 17:17:28 +0200 Subject: [PATCH] Return value of mb_get_info can be NULL This has been the case at least since PHP 5.4. Thanks to Girgias for pointing it out. It appears that there are several global variables internal to mbstring which can be queried via mb_get_info() and which could be NULL, but at the very least, we know that "mbstring.http_input" is one of them. --- Zend/Optimizer/zend_func_infos.h | 2 +- ext/mbstring/mbstring.stub.php | 4 ++-- ext/mbstring/mbstring_arginfo.h | 4 ++-- ext/mbstring/tests/mb_get_info_http_input.phpt | 10 ++++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 ext/mbstring/tests/mb_get_info_http_input.phpt diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h index 10f8d950ee0..3aefdf53df0 100644 --- a/Zend/Optimizer/zend_func_infos.h +++ b/Zend/Optimizer/zend_func_infos.h @@ -235,7 +235,7 @@ static const func_info_t func_infos[] = { F1("mb_convert_variables", MAY_BE_STRING|MAY_BE_FALSE), F1("mb_encode_numericentity", MAY_BE_STRING), F1("mb_decode_numericentity", MAY_BE_STRING), - F1("mb_get_info", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE), + F1("mb_get_info", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_NULL), #if defined(HAVE_MBREGEX) F1("mb_regex_encoding", MAY_BE_STRING|MAY_BE_BOOL), #endif diff --git a/ext/mbstring/mbstring.stub.php b/ext/mbstring/mbstring.stub.php index 0d04e34bc78..77d3fee67aa 100644 --- a/ext/mbstring/mbstring.stub.php +++ b/ext/mbstring/mbstring.stub.php @@ -171,10 +171,10 @@ function mb_decode_numericentity(string $string, array $map, ?string $encoding = function mb_send_mail(string $to, string $subject, string $message, array|string $additional_headers = [], ?string $additional_params = null): bool {} /** - * @return array|string|int|false + * @return array|string|int|false|null * @refcount 1 */ -function mb_get_info(string $type = "all"): array|string|int|false {} +function mb_get_info(string $type = "all"): array|string|int|false|null {} function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool {} diff --git a/ext/mbstring/mbstring_arginfo.h b/ext/mbstring/mbstring_arginfo.h index 3bf10789e0d..924c6864e54 100644 --- a/ext/mbstring/mbstring_arginfo.h +++ b/ext/mbstring/mbstring_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 0c9ac8888b8332557f7098cfb9d259757af8b3c6 */ + * Stub hash: 131af756402aecb88d2265f2a3d25aa5c66a7185 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_language, 0, 0, MAY_BE_STRING|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, language, IS_STRING, 1, "null") @@ -177,7 +177,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_send_mail, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, additional_params, IS_STRING, 1, "null") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_get_info, 0, 0, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_get_info, 0, 0, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\"all\"") ZEND_END_ARG_INFO() diff --git a/ext/mbstring/tests/mb_get_info_http_input.phpt b/ext/mbstring/tests/mb_get_info_http_input.phpt new file mode 100644 index 00000000000..5cfac7a8336 --- /dev/null +++ b/ext/mbstring/tests/mb_get_info_http_input.phpt @@ -0,0 +1,10 @@ +--TEST-- +mb_get_info("http_input") can return null +--EXTENSIONS-- +mbstring +--FILE-- + +--EXPECT-- +NULL