Skip to content

Commit 3af914d

Browse files
committed
ext/ldap: Fetch the values directly via hash API
1 parent d3dbcef commit 3af914d

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

ext/ldap/ldap.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,13 +2509,6 @@ static size_t _ldap_str_equal_to_const(const char *str, size_t str_len, const ch
25092509
}
25102510
/* }}} */
25112511

2512-
/* {{{ _ldap_hash_fetch */
2513-
static void _ldap_hash_fetch(zval *hashTbl, const char *key, zval **out)
2514-
{
2515-
*out = zend_hash_str_find(Z_ARRVAL_P(hashTbl), key, strlen(key));
2516-
}
2517-
/* }}} */
2518-
25192512
/* {{{ Perform multiple modifications as part of one operation */
25202513
PHP_FUNCTION(ldap_modify_batch)
25212514
{
@@ -2715,12 +2708,12 @@ PHP_FUNCTION(ldap_modify_batch)
27152708
fetched = zend_hash_index_find(Z_ARRVAL_P(mods), i);
27162709
mod = fetched;
27172710

2718-
zval *attrib_zv;
2719-
zval *modtype_zv;
2720-
zval *vals;
2721-
_ldap_hash_fetch(mod, LDAP_MODIFY_BATCH_ATTRIB, &attrib_zv);
2722-
_ldap_hash_fetch(mod, LDAP_MODIFY_BATCH_MODTYPE, &modtype_zv);
2723-
_ldap_hash_fetch(mod, LDAP_MODIFY_BATCH_VALUES, &vals);
2711+
zval *attrib_zv = zend_hash_str_find(Z_ARRVAL_P(mod), LDAP_MODIFY_BATCH_ATTRIB, strlen(LDAP_MODIFY_BATCH_ATTRIB));
2712+
ZEND_ASSERT(Z_TYPE_P(attrib_zv) == IS_STRING);
2713+
zval *modtype_zv = zend_hash_str_find(Z_ARRVAL_P(mod), LDAP_MODIFY_BATCH_MODTYPE, strlen(LDAP_MODIFY_BATCH_MODTYPE));
2714+
ZEND_ASSERT(Z_TYPE_P(modtype_zv) == IS_LONG);
2715+
zval *modification_values = zend_hash_str_find(Z_ARRVAL_P(mod), LDAP_MODIFY_BATCH_VALUES, strlen(LDAP_MODIFY_BATCH_VALUES));
2716+
ZEND_ASSERT(modification_values == NULL || Z_TYPE_P(modification_values) == IS_ARRAY);
27242717

27252718
/* map the modification type */
27262719
int ldap_operation;
@@ -2753,13 +2746,13 @@ PHP_FUNCTION(ldap_modify_batch)
27532746
}
27542747
else {
27552748
/* allocate space for the values as part of this modification */
2756-
uint32_t num_modification_values = zend_hash_num_elements(Z_ARRVAL_P(vals));
2749+
uint32_t num_modification_values = zend_hash_num_elements(Z_ARRVAL_P(modification_values));
27572750
ldap_mods[i]->mod_bvalues = safe_emalloc((num_modification_values+1), sizeof(struct berval *), 0);
27582751

27592752
/* for each value */
27602753
for (j = 0; j < num_modification_values; j++) {
27612754
/* fetch it */
2762-
fetched = zend_hash_index_find(Z_ARRVAL_P(vals), j);
2755+
fetched = zend_hash_index_find(Z_ARRVAL_P(modification_values), j);
27632756
zend_string *modval = zval_get_string(fetched);
27642757
if (EG(exception)) {
27652758
RETVAL_FALSE;

0 commit comments

Comments
 (0)