From 88ba9dc61b5186981db6e8dc82fa60227399eba7 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Thu, 7 Dec 2023 17:23:01 +0000 Subject: [PATCH] ext/mbstring: Always throw ValueErrors for invalid mb_http_input() type --- UPGRADING | 1 + ext/mbstring/mbstring.c | 4 ++++ ext/mbstring/tests/mb_http_input.phpt | 6 ------ ext/mbstring/tests/mb_http_input_errors.phpt | 22 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 ext/mbstring/tests/mb_http_input_errors.phpt diff --git a/UPGRADING b/UPGRADING index 58c60420aeb..6427fc43c21 100644 --- a/UPGRADING +++ b/UPGRADING @@ -34,6 +34,7 @@ PHP 8.4 UPGRADE NOTES - MBString: . mb_encode_numericentity() and mb_decode_numericentity() now check that the $map is only composed of integers, if not a ValueError is thrown. + . mb_http_input() now always throws a ValueError if the $type is invalid. - PDO_DBLIB: . setAttribute, DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER and DBLIB_ATTR_DATETIME_CONVERT diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index c01fbde3e81..3cc75abe37c 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -1271,6 +1271,10 @@ PHP_FUNCTION(mb_http_input) if (type == NULL) { encoding = MBSTRG(http_input_identify); + } else if (type_len != 1) { + zend_argument_value_error(1, + "must be one of \"G\", \"P\", \"C\", \"S\", \"I\", or \"L\""); + RETURN_THROWS(); } else { switch (*type) { case 'G': diff --git a/ext/mbstring/tests/mb_http_input.phpt b/ext/mbstring/tests/mb_http_input.phpt index a439b696d5f..3104c5b6ead 100644 --- a/ext/mbstring/tests/mb_http_input.phpt +++ b/ext/mbstring/tests/mb_http_input.phpt @@ -22,11 +22,6 @@ var_dump(mb_http_input('C')); var_dump(mb_http_input('S')); var_dump(mb_http_input('I')); var_dump(mb_http_input('L')); -try { - var_dump(mb_http_input('Q')); -} catch (ValueError $e) { - echo $e->getMessage(), "\n"; -} ?> --EXPECT-- @@ -41,4 +36,3 @@ array(1) { string(10) "ISO-8859-1" } string(10) "ISO-8859-1" -mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L" diff --git a/ext/mbstring/tests/mb_http_input_errors.phpt b/ext/mbstring/tests/mb_http_input_errors.phpt new file mode 100644 index 00000000000..88b3984c6bb --- /dev/null +++ b/ext/mbstring/tests/mb_http_input_errors.phpt @@ -0,0 +1,22 @@ +--TEST-- +mb_http_input() errors: +--EXTENSIONS-- +mbstring +--FILE-- +getMessage(), "\n"; +} +try { + var_dump(mb_http_input('Q')); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L" +mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L"