[php-src] master: ext/ldap: fix crash in ldap_exop_sync() when $response_data is omitted
| From: | lacatoire via ndossche | Date: | Fri, 30 Oct 2026 20:08:44 +0000 |
| Subject: | [php-src] master: ext/ldap: fix crash in ldap_exop_sync() when $response_data is omitted | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143038@lists.php.net to get a copy of this message | ||
Author: lacatoire (lacatoire)
Committer: ndossche (ndossche)
Date: 2026-10-30T21:07:37+01:00
Commit: https://github.com/php/php-src/commit/56bd75634f931745f35bbbde52aa92e319557ca1
Raw diff: https://github.com/php/php-src/commit/56bd75634f931745f35bbbde52aa92e319557ca1.diff
ext/ldap: fix crash in ldap_exop_sync() when $response_data is omitted
ldap_exop_sync() always takes the synchronous branch of php_ldap_exop(),
which assigns $response_data unconditionally. When the argument is not
passed, retdata is NULL and ZEND_TRY_ASSIGN_REF_STRINGL()/
ZEND_TRY_ASSIGN_REF_EMPTY_STRING() dereference it, so any successful
ldap_exop_sync($ldap, $oid) call segfaults. Guard the assignment the way
the $response_oid one already is.
Closes GH-23339.
Changed paths:
A ext/ldap/tests/ldap_exop_sync_without_response_data.phpt
M NEWS
M ext/ldap/ldap.c
Diff:
diff --git a/NEWS b/NEWS
index 798f849854c1..433aa7d0297c 100644
--- a/NEWS
+++ b/NEWS
@@ -111,6 +111,9 @@ PHP NEWS
properties after running out of memory while escaping a property name.
(adapik)
+- LDAP:
+ . Fix crash in ldap_exop_sync() when $response_data is omitted. (lacatoire)
+
- MBString:
. Fixed bug GH-23958 (truncated encoding names resolving to full names). (Kamil Tekiela)
. Fixed out-of-bounds read in php_mb_rfc1867_getword() on a multibyte lead
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 2b3cb0e8a706..4c9466749ea8 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -4129,10 +4129,12 @@ static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
}
if (lretdata) {
- ZEND_TRY_ASSIGN_REF_STRINGL(retdata, lretdata->bv_val, lretdata->bv_len);
+ if (retdata) {
+ ZEND_TRY_ASSIGN_REF_STRINGL(retdata, lretdata->bv_val, lretdata->bv_len);
+ }
ldap_memfree(lretdata->bv_val);
ldap_memfree(lretdata);
- } else {
+ } else if (retdata) {
ZEND_TRY_ASSIGN_REF_EMPTY_STRING(retdata);
}
diff --git a/ext/ldap/tests/ldap_exop_sync_without_response_data.phpt
b/ext/ldap/tests/ldap_exop_sync_without_response_data.phpt
new file mode 100644
index 000000000000..111900c6a05a
--- /dev/null
+++ b/ext/ldap/tests/ldap_exop_sync_without_response_data.phpt
@@ -0,0 +1,22 @@
+--TEST--
+ldap_exop_sync() - without the response_data argument
+--EXTENSIONS--
+ldap
+--SKIPIF--
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
+
+var_dump(
+ ldap_exop_sync($link, LDAP_EXOP_WHO_AM_I),
+ ldap_exop_sync($link, LDAP_EXOP_WHO_AM_I, null, null, $retdata),
+ $retdata
+);
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+string(%d) "dn:%s"