Skip to content

Commit 8dbb532

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix freeing uninitialized memory in LDAP sort control parsing
2 parents d23da75 + a15654e commit 8dbb532

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

ext/ldap/ldap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
585585

586586
uint32_t num_keys = zend_hash_num_elements(Z_ARRVAL_P(val));
587587
sort_keys = safe_emalloc((num_keys+1), sizeof(LDAPSortKey*), 0);
588+
memset(sort_keys, 0, (num_keys+1) * sizeof(LDAPSortKey*));
588589
tmpstrings1 = safe_emalloc(num_keys, sizeof(zend_string*), 0);
589590
tmpstrings2 = safe_emalloc(num_keys, sizeof(zend_string*), 0);
590591
num_tmpstrings1 = 0;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
ldap_search(): malformed sort control (sort key missing "attr") must not free uninitialized memory
3+
--EXTENSIONS--
4+
ldap
5+
--FILE--
6+
<?php
7+
// No server needed: the control array is validated before the search is sent.
8+
// A sort key missing "attr" makes php_ldap_control_from_array() bail mid-loop;
9+
// the failure cleanup must not walk/free the partially built sort_keys array.
10+
$ld = ldap_connect("ldap://127.0.0.1:389");
11+
12+
try {
13+
ldap_search($ld, "dc=example,dc=com", "(objectClass=*)", [], 0, -1, -1, LDAP_DEREF_NEVER, [
14+
[
15+
'oid' => LDAP_CONTROL_SORTREQUEST,
16+
'value' => [
17+
['attr' => 'cn'],
18+
['reverse' => true],
19+
],
20+
],
21+
]);
22+
} catch (\ValueError $e) {
23+
echo $e->getMessage(), "\n";
24+
}
25+
26+
echo "ok\n";
27+
?>
28+
--EXPECT--
29+
ldap_search(): Sort key list must have an "attr" key
30+
ok

0 commit comments

Comments
 (0)