From 52fe9b0ef1a1dd31febe07707b1cfd01f7ff8cdc Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 11 Oct 2024 12:06:23 +0100 Subject: [PATCH 1/2] Fix GH-16354 convert GMP to number failure. zend_parse_arg_long_slow/zend_null_arg_deprecated handle nullable as 2nd (or +) argument so here we trigger a TypeError exception in case we deal with null at 1st argument. --- ext/gmp/gmp.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 02eb30bacb730..923fa9bf2e0c4 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -619,6 +619,15 @@ static zend_result convert_to_gmp(mpz_t gmpnumber, zval *val, zend_long base, ui case IS_STRING: { return convert_zstr_to_gmp(gmpnumber, Z_STR_P(val), base, arg_pos); } + case IS_NULL: { + /** + * zend_parse_arg_long_slow support nullable argument but expects it + * to be the 2nd, and onward, argument or non null but at any place. + **/ + zend_type_error( + "Number must be of type GMP|string|int, null given"); + return FAILURE; + } default: { zend_long lval; if (!zend_parse_arg_long_slow(val, &lval, arg_pos)) { From 64c6a6611438c99ce77ec6466f160dbc7b05925e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 11 Oct 2024 12:17:28 +0100 Subject: [PATCH 2/2] add/update test --- ext/gmp/tests/gh16368.phpt | 12 ++++++++++++ ext/gmp/tests/gmp_strict_types.phpt | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 ext/gmp/tests/gh16368.phpt diff --git a/ext/gmp/tests/gh16368.phpt b/ext/gmp/tests/gh16368.phpt new file mode 100644 index 0000000000000..356e13d7e8d69 --- /dev/null +++ b/ext/gmp/tests/gh16368.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug GH-16368: gmp_init on first argument as null. +--EXTENSIONS-- +gmp +--FILE-- + +--EXPECTF-- +Warning: Undefined variable $inexistent in %s on line %d + +Deprecated: gmp_init(): Passing null to parameter #1 ($num) of type string|int is deprecated in %s on line %d diff --git a/ext/gmp/tests/gmp_strict_types.phpt b/ext/gmp/tests/gmp_strict_types.phpt index a63f2ef5059db..71bdf67d32110 100644 --- a/ext/gmp/tests/gmp_strict_types.phpt +++ b/ext/gmp/tests/gmp_strict_types.phpt @@ -53,5 +53,5 @@ object(GMP)#2 (1) { gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, float given gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, bool given gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, bool given -gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, null given +Number must be of type GMP|string|int, null given gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, array given