From 9f645c976522e84a0765e2bb7b32e94ac7d43c39 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Fri, 16 Oct 2026 15:41:47 +0200 Subject: [PATCH 1/2] ext/ldap: report the type of the rejected value in ldap_modify_batch() --- ext/ldap/ldap.c | 4 +-- .../ldap_modify_batch_programming_error.phpt | 2 +- .../ldap_modify_batch_type_error_value.phpt | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 ext/ldap/tests/ldap_modify_batch_type_error_value.phpt diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 8c0a04729deb..bd774c776574 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -2694,7 +2694,7 @@ PHP_FUNCTION(ldap_modify_batch) ZVAL_DEREF(modtype_zv); if (UNEXPECTED(Z_TYPE_P(modtype_zv) != IS_LONG)) { - zend_argument_type_error(3, "the value for option \"" LDAP_MODIFY_BATCH_MODTYPE "\" must be of type int, %s given", zend_zval_value_name(attrib)); + zend_argument_type_error(3, "the value for option \"" LDAP_MODIFY_BATCH_MODTYPE "\" must be of type int, %s given", zend_zval_value_name(modtype_zv)); RETURN_THROWS(); } zend_long modtype = Z_LVAL_P(modtype_zv); @@ -2730,7 +2730,7 @@ PHP_FUNCTION(ldap_modify_batch) ZVAL_DEREF(modification_values_zv); if (Z_TYPE_P(modification_values_zv) != IS_ARRAY) { - zend_argument_type_error(3, "the value for option \"" LDAP_MODIFY_BATCH_VALUES "\" must be of type array, %s given", zend_zval_value_name(attrib)); + zend_argument_type_error(3, "the value for option \"" LDAP_MODIFY_BATCH_VALUES "\" must be of type array, %s given", zend_zval_value_name(modification_values_zv)); RETURN_THROWS(); } diff --git a/ext/ldap/tests/ldap_modify_batch_programming_error.phpt b/ext/ldap/tests/ldap_modify_batch_programming_error.phpt index b123f437aa3f..b180d15d13b8 100644 --- a/ext/ldap/tests/ldap_modify_batch_programming_error.phpt +++ b/ext/ldap/tests/ldap_modify_batch_programming_error.phpt @@ -251,7 +251,7 @@ ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modificatio ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must only contain the keys "attrib", "modtype", and "values" TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "attrib" must be of type string, int given ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "attrib" must not contain null bytes -TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be of type int, string given +TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be of type int, stdClass given ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be LDAP_MODIFY_BATCH_ADD, LDAP_MODIFY_BATCH_REMOVE, LDAP_MODIFY_BATCH_REPLACE, or LDAP_MODIFY_BATCH_REMOVE_ALL ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must not contain the "values" option when option "modtype" is LDAP_MODIFY_BATCH_REMOVE_ALL ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must contain the "values" option when the "modtype" option is not LDAP_MODIFY_BATCH_REMOVE_ALL diff --git a/ext/ldap/tests/ldap_modify_batch_type_error_value.phpt b/ext/ldap/tests/ldap_modify_batch_type_error_value.phpt new file mode 100644 index 000000000000..f7374bce63e6 --- /dev/null +++ b/ext/ldap/tests/ldap_modify_batch_type_error_value.phpt @@ -0,0 +1,25 @@ +--TEST-- +ldap_modify_batch(): the type errors name the type of the rejected value +--EXTENSIONS-- +ldap +--FILE-- + "a", "modtype" => [], "values" => ["v"]]], + [["attrib" => "a", "modtype" => "x", "values" => ["v"]]], + [["attrib" => "a", "modtype" => LDAP_MODIFY_BATCH_ADD, "values" => "v"]], + [["attrib" => "a", "modtype" => LDAP_MODIFY_BATCH_ADD, "values" => 5]], +] as $mods) { + try { + ldap_modify_batch($l, "cn=x", $mods); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be of type int, array given +TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be of type int, string given +TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be of type array, string given +TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be of type array, int given From e623520d84fcb3fae7927995fe048df761b19788 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Thu, 12 Nov 2026 08:55:41 +0100 Subject: [PATCH 2/2] ext/ldap: use non-string values in the ldap_modify_batch() type error test --- ext/ldap/tests/ldap_modify_batch_type_error_value.phpt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/ldap/tests/ldap_modify_batch_type_error_value.phpt b/ext/ldap/tests/ldap_modify_batch_type_error_value.phpt index f7374bce63e6..1db6b014e7b7 100644 --- a/ext/ldap/tests/ldap_modify_batch_type_error_value.phpt +++ b/ext/ldap/tests/ldap_modify_batch_type_error_value.phpt @@ -7,7 +7,7 @@ ldap $l = ldap_connect('ldap://127.0.0.1:1'); foreach ([ [["attrib" => "a", "modtype" => [], "values" => ["v"]]], - [["attrib" => "a", "modtype" => "x", "values" => ["v"]]], + [["attrib" => "a", "modtype" => 1.5, "values" => ["v"]]], [["attrib" => "a", "modtype" => LDAP_MODIFY_BATCH_ADD, "values" => "v"]], [["attrib" => "a", "modtype" => LDAP_MODIFY_BATCH_ADD, "values" => 5]], ] as $mods) { @@ -20,6 +20,6 @@ foreach ([ ?> --EXPECT-- TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be of type int, array given -TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be of type int, string given -TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be of type array, string given +TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be of type int, float given +TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be of type array, null given TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be of type array, int given