Skip to content

Commit db57561

Browse files
committed
ext/ldap: Check that attribute values is a list before traversal
1 parent 9e91810 commit db57561

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

ext/ldap/ldap.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ PHP_FUNCTION(ldap_dn2ufn)
21942194
static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
21952195
{
21962196
zval *serverctrls = NULL;
2197-
zval *link, *entry, *value, *ivalue;
2197+
zval *link, *entry, *value;
21982198
ldap_linkdata *ld;
21992199
char *dn;
22002200
LDAPMod **ldap_mods;
@@ -2279,18 +2279,21 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
22792279
ldap_mods[i]->mod_bvalues = NULL;
22802280
goto cleanup;
22812281
}
2282+
if (!zend_array_is_list(Z_ARRVAL_P(value))) {
2283+
zend_argument_value_error(3, "must be a list of attribute values");
2284+
RETVAL_FALSE;
2285+
num_berval[i] = 0;
2286+
num_attribs = i + 1;
2287+
ldap_mods[i]->mod_bvalues = NULL;
2288+
goto cleanup;
2289+
}
22822290

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

22862294
for (j = 0; j < num_values; j++) {
2287-
if ((ivalue = zend_hash_index_find(Z_ARRVAL_P(value), j)) == NULL) {
2288-
zend_argument_value_error(3, "must contain arrays with consecutive integer indices starting from 0");
2289-
num_berval[i] = j;
2290-
num_attribs = i + 1;
2291-
RETVAL_FALSE;
2292-
goto cleanup;
2293-
}
2295+
zval *ivalue = zend_hash_index_find(Z_ARRVAL_P(value), j);
2296+
ZEND_ASSERT(ivalue != NULL);
22942297
convert_to_string(ivalue);
22952298
if (EG(exception)) {
22962299
num_berval[i] = j;

ext/ldap/tests/ldap_add_modify_delete_programming_errors.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ 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
146146
ValueError: ldap_add(): Argument #3 ($entry) list of attribute values must not be empty
147-
ValueError: ldap_add(): Argument #3 ($entry) must contain arrays with consecutive integer indices starting from 0
147+
ValueError: ldap_add(): Argument #3 ($entry) must be a list of attribute values
148148

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

0 commit comments

Comments
 (0)