Skip to content

Commit b03438b

Browse files
committed
Fix crash in LDAP search functions during argument validation
1 parent 5ecc078 commit b03438b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/ldap/ldap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,11 +1602,15 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16021602

16031603
if (!base_dn_str) {
16041604
zend_argument_type_error(2, "must be of type string when argument #1 ($ldap) is a resource");
1605+
ret = 0;
1606+
goto cleanup;
16051607
}
16061608
ldap_base_dn = zend_string_copy(base_dn_str);
16071609

16081610
if (!filter_str) {
16091611
zend_argument_type_error(3, "must be of type string when argument #1 ($ldap) is a resource");
1612+
ret = 0;
1613+
goto cleanup;
16101614
}
16111615
ldap_filter = zend_string_copy(filter_str);
16121616

ext/ldap/tests/ldap_search_error.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ try {
3939
echo $exception->getMessage() . "\n";
4040
}
4141

42+
try {
43+
ldap_search($link, [], []);
44+
} catch (TypeError $exception) {
45+
echo $exception->getMessage() . "\n";
46+
}
47+
48+
try {
49+
ldap_search($link, "", []);
50+
} catch (TypeError $exception) {
51+
echo $exception->getMessage() . "\n";
52+
}
53+
4254
?>
4355
--EXPECTF--
4456
Warning: ldap_search(): Search: No such object in %s on line %d
@@ -49,3 +61,5 @@ bool(false)
4961
ldap_search(): Argument #1 ($ldap) cannot be empty
5062
ldap_search(): Argument #2 ($base) must have the same number of elements as the links array
5163
ldap_search(): Argument #3 ($filter) must have the same number of elements as the links array
64+
ldap_search(): Argument #2 ($base) must be of type string when argument #1 ($ldap) is a resource
65+
ldap_search(): Argument #3 ($filter) must be of type string when argument #1 ($ldap) is a resource

0 commit comments

Comments
 (0)