[php-src] PR #25793: Reject LDAP entries and references whose result was freed
| From: | lacatoire | Date: | Thu, 26 Nov 2026 16:17:52 +0000 |
| Subject: | [php-src] PR #25793: Reject LDAP entries and references whose result was freed | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41063@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25793
Author: lacatoire
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
```php
<?php
$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
```