Skip to content

Commit bfa2cfc

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix NULL deref on high modification key
2 parents ecd2872 + c905d59 commit bfa2cfc

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Diff for: NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ PHP NEWS
2626

2727
- LDAP:
2828
. Fixed bug GH-17776 (LDAP_OPT_X_TLS_* options can't be overridden). (Remi)
29+
. Fix NULL deref on high modification key. (nielsdos)
2930

3031
- libxml:
3132
. Fixed custom external entity loader returning an invalid resource leading

Diff for: ext/ldap/ldap.c

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

27892789
/* for each modification */
2790-
for (i = 0; i < num_mods; i++) {
2790+
i = 0;
2791+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(mods), fetched) {
27912792
/* allocate the modification struct */
27922793
ldap_mods[i] = safe_emalloc(1, sizeof(LDAPMod), 0);
27932794

27942795
/* fetch the relevant data */
2795-
fetched = zend_hash_index_find(Z_ARRVAL_P(mods), i);
27962796
mod = fetched;
27972797

27982798
_ldap_hash_fetch(mod, LDAP_MODIFY_BATCH_ATTRIB, &attrib);
@@ -2857,7 +2857,9 @@ PHP_FUNCTION(ldap_modify_batch)
28572857
/* NULL-terminate values */
28582858
ldap_mods[i]->mod_bvalues[num_modvals] = NULL;
28592859
}
2860-
}
2860+
2861+
i++;
2862+
} ZEND_HASH_FOREACH_END();
28612863

28622864
/* NULL-terminate modifications */
28632865
ldap_mods[num_mods] = NULL;

Diff for: 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)