Skip to content

Commit 9e91810

Browse files
committed
ext/ldap: Ensure list of attribute values is not empty
1 parent 09ffa28 commit 9e91810

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

ext/ldap/ldap.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,14 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
22712271
} else {
22722272
SEPARATE_ARRAY(value);
22732273
num_values = zend_hash_num_elements(Z_ARRVAL_P(value));
2274+
if (num_values == 0) {
2275+
zend_argument_value_error(3, "list of attribute values must not be empty");
2276+
RETVAL_FALSE;
2277+
num_berval[i] = 0;
2278+
num_attribs = i + 1;
2279+
ldap_mods[i]->mod_bvalues = NULL;
2280+
goto cleanup;
2281+
}
22742282

22752283
num_berval[i] = num_values;
22762284
ldap_mods[i]->mod_bvalues = safe_emalloc((num_values + 1), sizeof(struct berval *), 0);

ext/ldap/tests/ldap_add_modify_delete_programming_errors.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ bool(false)
143143
Warning: ldap_add(): Add: Can't contact LDAP server in %s on line %d
144144
bool(false)
145145
Error: Object of class stdClass could not be converted to string
146-
147-
Warning: ldap_add(): Add: Can't contact LDAP server in %s on line %d
148-
bool(false)
146+
ValueError: ldap_add(): Argument #3 ($entry) list of attribute values must not be empty
149147
ValueError: ldap_add(): Argument #3 ($entry) must contain arrays with consecutive integer indices starting from 0
150148

151149
Warning: Array to string conversion in %s on line %d

ext/ldap/tests/ldap_add_modify_delete_references_programming_errors.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ try {
7676
?>
7777
--EXPECTF--
7878
Error: Object of class stdClass could not be converted to string
79-
80-
Warning: ldap_add(): Add: Can't contact LDAP server in %s on line %d
81-
bool(false)
79+
ValueError: ldap_add(): Argument #3 ($entry) list of attribute values must not be empty
8280

8381
Warning: Array to string conversion in %s on line %d
8482

0 commit comments

Comments
 (0)