Skip to content

Commit 0a39b48

Browse files
committed
ext/ldap: Use zend_array_is_list() API to check "values" array
1 parent 6f50850 commit 0a39b48

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

ext/ldap/ldap.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,7 @@ PHP_FUNCTION(ldap_modify_batch)
25272527
zval *fetched;
25282528
char *dn;
25292529
size_t dn_len;
2530-
int i, j, k;
2530+
int i, j;
25312531
int num_mods, num_modprops, num_modvals;
25322532
LDAPMod **ldap_mods;
25332533
LDAPControl **lserverctrls = NULL;
@@ -2682,27 +2682,17 @@ PHP_FUNCTION(ldap_modify_batch)
26822682
}
26832683

26842684
SEPARATE_ARRAY(modinfo);
2685+
const HashTable *modification_values = Z_ARRVAL_P(modinfo);
26852686
/* is the array not empty? */
2686-
zend_hash_internal_pointer_reset(Z_ARRVAL_P(modinfo));
2687-
num_modvals = zend_hash_num_elements(Z_ARRVAL_P(modinfo));
2688-
if (num_modvals == 0) {
2689-
zend_value_error("%s(): Option \"" LDAP_MODIFY_BATCH_VALUES "\" must not be empty", get_active_function_name());
2687+
uint32_t num_modification_values = zend_hash_num_elements(modification_values);
2688+
if (num_modification_values == 0) {
2689+
zend_argument_value_error(3, "the value for option \"" LDAP_MODIFY_BATCH_VALUES "\" must not be empty");
26902690
RETURN_THROWS();
26912691
}
2692-
2693-
/* are its keys integers? */
2694-
if (zend_hash_get_current_key_type(Z_ARRVAL_P(modinfo)) != HASH_KEY_IS_LONG) {
2695-
zend_value_error("%s(): Option \"" LDAP_MODIFY_BATCH_VALUES "\" must be integer-indexed", get_active_function_name());
2692+
if (!zend_array_is_list(modification_values)) {
2693+
zend_argument_value_error(3, "the value for option \"" LDAP_MODIFY_BATCH_VALUES "\" must be a list");
26962694
RETURN_THROWS();
26972695
}
2698-
2699-
/* are the keys consecutive? */
2700-
for (k = 0; k < num_modvals; k++) {
2701-
if ((fetched = zend_hash_index_find(Z_ARRVAL_P(modinfo), k)) == NULL) {
2702-
zend_value_error("%s(): Option \"" LDAP_MODIFY_BATCH_VALUES "\" must have consecutive integer indices starting from 0", get_active_function_name());
2703-
RETURN_THROWS();
2704-
}
2705-
}
27062696
}
27072697

27082698
zend_hash_move_forward(Z_ARRVAL_P(mod));

ext/ldap/tests/ldap_modify_batch_programming_error.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ ValueError: ldap_modify_batch(): Option "modtype" must be one of the LDAP_MODIFY
269269
ValueError: ldap_modify_batch(): If option "modtype" is LDAP_MODIFY_BATCH_REMOVE_ALL, option "values" cannot be provided
270270
ValueError: ldap_modify_batch(): If option "modtype" is not LDAP_MODIFY_BATCH_REMOVE_ALL, option "values" must be provided
271271
TypeError: ldap_modify_batch(): Option "values" must be of type array, string given
272-
ValueError: ldap_modify_batch(): Option "values" must not be empty
273-
ValueError: ldap_modify_batch(): Option "values" must be integer-indexed
274-
ValueError: ldap_modify_batch(): Option "values" must have consecutive integer indices starting from 0
272+
ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must not be empty
273+
ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be a list
274+
ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be a list
275275
ValueError: ldap_modify_batch(): Required option "attrib" is missing
276276
ValueError: ldap_modify_batch(): Required option "modtype" is missing

0 commit comments

Comments
 (0)