Skip to content

Fix freeing uninitialized memory in LDAP sort control parsing#22342

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix-ldap-sort-control
Open

Fix freeing uninitialized memory in LDAP sort control parsing#22342
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix-ldap-sort-control

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

_php_ldap_control_from_array() allocated the sort_keys array with safe_emalloc() and wrote its NULL terminator only after the per-key loop. A sort key missing the "attr" entry bails out of the loop early, so the array is partially uninitialized when the failure cleanup walks it as a NULL-terminated list and efree()s the unwritten slots. Allocate it zeroed with ecalloc() so those slots read NULL; the sibling tmpstrings arrays are freed by a counter and stay safe_emalloc. Reachable from userland via the $controls argument of ldap_search() and the other control-taking LDAP functions.

_php_ldap_control_from_array() allocated the sort_keys array with
safe_emalloc() and only wrote its NULL terminator after the per-key loop
finished. A sort key missing the "attr" entry makes the loop bail out
early, leaving the array partially uninitialized; the failure cleanup
then walks it as a NULL-terminated list and calls efree() on the
uninitialized slots. Allocate the array zeroed with ecalloc() so the
unwritten slots are NULL. Reachable from userland via the $controls
argument of ldap_search() and the other control-taking LDAP functions.

Closes phpGH-22342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant