Skip to content

Commit d116066

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-21262: ldap_modify() too strict controls argument validation.
2 parents 3b609a1 + aa44392 commit d116066

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

ext/ldap/ldap.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,9 +2340,14 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, bool ext)
23402340
SEPARATE_ARRAY(attribute_values);
23412341
uint32_t num_values = zend_hash_num_elements(Z_ARRVAL_P(attribute_values));
23422342
if (num_values == 0) {
2343-
zend_argument_value_error(3, "attribute \"%s\" must be a non-empty list of attribute values", ZSTR_VAL(attribute));
2344-
RETVAL_FALSE;
2345-
goto cleanup;
2343+
if (UNEXPECTED(oper == LDAP_MOD_ADD)) {
2344+
zend_argument_value_error(3, "attribute \"%s\" must be a non-empty list of attribute values", ZSTR_VAL(attribute));
2345+
RETVAL_FALSE;
2346+
goto cleanup;
2347+
}
2348+
/* When we modify, we mean we delete the attribute */
2349+
attribute_index++;
2350+
continue;
23462351
}
23472352
if (!php_ldap_is_numerically_indexed_array(Z_ARRVAL_P(attribute_values))) {
23482353
zend_argument_value_error(3, "attribute \"%s\" must be an array of attribute values with numeric keys", ZSTR_VAL(attribute));

ext/ldap/tests/gh21262.phpt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
GH-21262 (ldap_modify() too strict controls argument validation)
3+
--EXTENSIONS--
4+
ldap
5+
--FILE--
6+
<?php
7+
/* We are assuming 3333 is not connectable */
8+
$ldap = ldap_connect('ldap://127.0.0.1:3333');
9+
$valid_dn = "cn=userA,something";
10+
11+
$entry_with_empty_array = [
12+
'attribute1' => 'value',
13+
'attribute2' => [],
14+
];
15+
16+
// ldap_add() should still reject empty arrays
17+
try {
18+
ldap_add($ldap, $valid_dn, $entry_with_empty_array);
19+
} catch (ValueError $e) {
20+
echo $e->getMessage(), PHP_EOL;
21+
}
22+
23+
// ldap_mod_add() should still reject empty arrays
24+
try {
25+
ldap_mod_add($ldap, $valid_dn, $entry_with_empty_array);
26+
} catch (ValueError $e) {
27+
echo $e->getMessage(), PHP_EOL;
28+
}
29+
30+
// ldap_modify() should accept empty arrays (delete attribute)
31+
try {
32+
@ldap_modify($ldap, $valid_dn, $entry_with_empty_array);
33+
echo "ldap_modify: no ValueError thrown", PHP_EOL;
34+
} catch (ValueError $e) {
35+
echo "ldap_modify: UNEXPECTED ValueError: ", $e->getMessage(), PHP_EOL;
36+
}
37+
38+
// ldap_mod_del() should accept empty arrays (delete attribute)
39+
try {
40+
@ldap_mod_del($ldap, $valid_dn, $entry_with_empty_array);
41+
echo "ldap_mod_del: no ValueError thrown", PHP_EOL;
42+
} catch (ValueError $e) {
43+
echo "ldap_mod_del: UNEXPECTED ValueError: ", $e->getMessage(), PHP_EOL;
44+
}
45+
?>
46+
--EXPECT--
47+
ldap_add(): Argument #3 ($entry) attribute "attribute2" must be a non-empty list of attribute values
48+
ldap_mod_add(): Argument #3 ($entry) attribute "attribute2" must be a non-empty list of attribute values
49+
ldap_modify: no ValueError thrown
50+
ldap_mod_del: no ValueError thrown

0 commit comments

Comments
 (0)