Skip to content

Commit 57871b0

Browse files
committed
Fixed GH-18902: ldap_exop/ldap_exop_sync assert triggered on empty request OID
1 parent a36b8fd commit 57871b0

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

ext/ldap/ldap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4036,7 +4036,12 @@ static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
40364036
LDAPControl **lserverctrls = NULL;
40374037
int rc, msgid;
40384038

4039-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS|S!a!zz", &link, ldap_link_ce, &reqoid, &reqdata, &serverctrls, &retdata, &retoid) != SUCCESS) {
4039+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP|S!a!zz", &link, ldap_link_ce, &reqoid, &reqdata, &serverctrls, &retdata, &retoid) != SUCCESS) {
4040+
RETURN_THROWS();
4041+
}
4042+
4043+
if (ZSTR_LEN(reqoid) == 0) {
4044+
zend_argument_value_error(2, "cannot be empty");
40404045
RETURN_THROWS();
40414046
}
40424047

ext/ldap/tests/gh18902.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
GH-17704 (ldap_search fails when $attributes contains a non-packed array with numerical keys)
3+
--EXTENSIONS--
4+
ldap
5+
--FILE--
6+
<?php
7+
$conn = ldap_connect();
8+
try {
9+
ldap_exop($conn,null);
10+
} catch (\ValueError $e) {
11+
echo $e->getMessage(), PHP_EOL;
12+
}
13+
14+
try {
15+
ldap_exop($conn,"\0");
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage(), PHP_EOL;
18+
}
19+
20+
try {
21+
ldap_exop_sync($conn,"");
22+
} catch (\ValueError $e) {
23+
echo $e->getMessage(), PHP_EOL;
24+
}
25+
26+
try {
27+
ldap_exop_sync($conn,"test\0");
28+
} catch (\ValueError $e) {
29+
echo $e->getMessage(), PHP_EOL;
30+
}
31+
?>
32+
--EXPECTF--
33+
34+
Deprecated: ldap_exop(): Passing null to parameter #2 ($request_oid) of type string is deprecated in %s on line %d
35+
ldap_exop(): Argument #2 ($request_oid) cannot be empty
36+
ldap_exop(): Argument #2 ($request_oid) must not contain any null bytes
37+
ldap_exop_sync(): Argument #2 ($request_oid) cannot be empty
38+
ldap_exop_sync(): Argument #2 ($request_oid) must not contain any null bytes

0 commit comments

Comments
 (0)