Skip to content

Commit 09ffa28

Browse files
committed
ext/ldap: Handle attribute => value case directly
1 parent 08bf506 commit 09ffa28

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

ext/ldap/ldap.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,29 +2251,30 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
22512251
value = zend_hash_get_current_data(Z_ARRVAL_P(entry));
22522252

22532253
ZVAL_DEREF(value);
2254+
/* If the attribute takes a single value it can be passed directly instead of as a list with one element */
2255+
/* allow for arrays with one element, no allowance for arrays with none but probably not required, gerrit thomson. */
22542256
if (Z_TYPE_P(value) != IS_ARRAY) {
2255-
num_values = 1;
2256-
} else {
2257-
SEPARATE_ARRAY(value);
2258-
num_values = zend_hash_num_elements(Z_ARRVAL_P(value));
2259-
}
2260-
2261-
num_berval[i] = num_values;
2262-
ldap_mods[i]->mod_bvalues = safe_emalloc((num_values + 1), sizeof(struct berval *), 0);
2263-
2264-
/* allow for arrays with one element, no allowance for arrays with none but probably not required, gerrit thomson. */
2265-
if ((num_values == 1) && (Z_TYPE_P(value) != IS_ARRAY)) {
22662257
convert_to_string(value);
22672258
if (EG(exception)) {
22682259
RETVAL_FALSE;
22692260
num_berval[i] = 0;
22702261
num_attribs = i + 1;
2262+
ldap_mods[i]->mod_bvalues = NULL;
22712263
goto cleanup;
22722264
}
2265+
num_berval[i] = 1;
2266+
ldap_mods[i]->mod_bvalues = safe_emalloc(2, sizeof(struct berval *), 0);
22732267
ldap_mods[i]->mod_bvalues[0] = (struct berval *) emalloc (sizeof(struct berval));
22742268
ldap_mods[i]->mod_bvalues[0]->bv_val = Z_STRVAL_P(value);
22752269
ldap_mods[i]->mod_bvalues[0]->bv_len = Z_STRLEN_P(value);
2270+
ldap_mods[i]->mod_bvalues[1] = NULL;
22762271
} else {
2272+
SEPARATE_ARRAY(value);
2273+
num_values = zend_hash_num_elements(Z_ARRVAL_P(value));
2274+
2275+
num_berval[i] = num_values;
2276+
ldap_mods[i]->mod_bvalues = safe_emalloc((num_values + 1), sizeof(struct berval *), 0);
2277+
22772278
for (j = 0; j < num_values; j++) {
22782279
if ((ivalue = zend_hash_index_find(Z_ARRVAL_P(value), j)) == NULL) {
22792280
zend_argument_value_error(3, "must contain arrays with consecutive integer indices starting from 0");
@@ -2293,8 +2294,9 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
22932294
ldap_mods[i]->mod_bvalues[j]->bv_val = Z_STRVAL_P(ivalue);
22942295
ldap_mods[i]->mod_bvalues[j]->bv_len = Z_STRLEN_P(ivalue);
22952296
}
2297+
ldap_mods[i]->mod_bvalues[num_values] = NULL;
22962298
}
2297-
ldap_mods[i]->mod_bvalues[num_values] = NULL;
2299+
22982300
zend_hash_move_forward(Z_ARRVAL_P(entry));
22992301
}
23002302
ldap_mods[num_attribs] = NULL;

0 commit comments

Comments
 (0)