Skip to content

Commit ec6e2c5

Browse files
committed
Fix NULL deref on high modification key
We should re-index in the loop.
1 parent 8849a53 commit ec6e2c5

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

ext/ldap/ldap.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -2785,12 +2785,12 @@ PHP_FUNCTION(ldap_modify_batch)
27852785
ldap_mods = safe_emalloc((num_mods+1), sizeof(LDAPMod *), 0);
27862786

27872787
/* for each modification */
2788-
for (i = 0; i < num_mods; i++) {
2788+
i = 0;
2789+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(mods), fetched) {
27892790
/* allocate the modification struct */
27902791
ldap_mods[i] = safe_emalloc(1, sizeof(LDAPMod), 0);
27912792

27922793
/* fetch the relevant data */
2793-
fetched = zend_hash_index_find(Z_ARRVAL_P(mods), i);
27942794
mod = fetched;
27952795

27962796
_ldap_hash_fetch(mod, LDAP_MODIFY_BATCH_ATTRIB, &attrib);
@@ -2855,7 +2855,9 @@ PHP_FUNCTION(ldap_modify_batch)
28552855
/* NULL-terminate values */
28562856
ldap_mods[i]->mod_bvalues[num_modvals] = NULL;
28572857
}
2858-
}
2858+
2859+
i++;
2860+
} ZEND_HASH_FOREACH_END();
28592861

28602862
/* NULL-terminate modifications */
28612863
ldap_mods[num_mods] = NULL;

ext/ldap/tests/ldap_modify_batch_error.phpt

+13
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ $mods = array(
5959
)
6060
);
6161

62+
var_dump(ldap_modify_batch($link, "dc=my-domain,$base", $mods));
63+
64+
// high key with invalid attribute type
65+
$mods = [
66+
99999 => [
67+
"attrib" => "weirdAttribute",
68+
"modtype" => LDAP_MODIFY_BATCH_ADD,
69+
"values" => ["value1"],
70+
],
71+
];
6272
var_dump(ldap_modify_batch($link, "dc=my-domain,$base", $mods));
6373
?>
6474
--CLEAN--
@@ -81,3 +91,6 @@ bool(false)
8191

8292
Warning: ldap_modify_batch(): Batch Modify: Undefined attribute type in %s on line %d
8393
bool(false)
94+
95+
Warning: ldap_modify_batch(): Batch Modify: Undefined attribute type in %s on line %d
96+
bool(false)

0 commit comments

Comments
 (0)