Skip to content

Reject LDAP entries and references whose result was freed - #25793

Open
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/ldap-free-result-entry-uaf-PHP-8.4
Open

lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/ldap-free-result-entry-uaf-PHP-8.4

Conversation

@lacatoire

@lacatoire lacatoire commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

LDAP\ResultEntry objects (entries and references) keep pointers into the LDAPMessage that ldap_free_result() frees, and the functions taking an entry never check that the result is still open, so using an entry after ldap_free_result() reads freed memory. Check it, like the functions taking an LDAP\Result already do.

To reproduce

$l = ldap_connect("ldap://127.0.0.1:3899");
ldap_set_option($l, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($l, 'cn=admin,dc=x', 'secret');
$r = ldap_search($l, "dc=x", "(cn=userA)");
$e = ldap_first_entry($l, $r);
var_dump(ldap_get_dn($l, $e));
ldap_free_result($r);
var_dump(ldap_get_dn($l, $e));

Before (PHP 8.4.28, OpenLDAP server with one entry):

string(13) "cn=userA,dc=x"
Assertion failed: LBER_VALID( ber ) (decode.c: ber_scanf: 750)

and the process aborts; under valgrind, Invalid read of size 8 in ldap_get_dn.

After:

string(13) "cn=userA,dc=x"

Fatal error: Uncaught Error: LDAP result has already been closed

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