Skip to content

Commit

Permalink
ext/ldap: Fix phpGH-16101 (Segfaults in php_ldap_do_search() when LDA…
Browse files Browse the repository at this point in the history
…Ps is not a list)
  • Loading branch information
Girgias committed Sep 28, 2024
1 parent 15a0c3a commit 44f48dc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ PHP NEWS
- LDAP:
. Fixed bug GH-16032 (Various NULL pointer dereferencements in
ldap_modify_batch()). (Girgias)
. Fixed bug GH-16101 (Segfault in ldap_list(), ldap_read(), and ldap_search()
when LDAPs array is not a list). (Girgias)

- PHPDBG:
. Fixed bug GH-15901 (phpdbg: Assertion failure on i funcs). (cmb)
Expand Down
5 changes: 5 additions & 0 deletions ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,11 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
ret = 0;
goto cleanup;
}
if (!zend_array_is_list(Z_ARRVAL_P(link))) {
zend_argument_value_error(1, "must be a list");
ret = 0;
goto cleanup;
}

if (base_dn_ht) {
nbases = zend_hash_num_elements(base_dn_ht);
Expand Down
25 changes: 25 additions & 0 deletions ext/ldap/tests/gh16101.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Bug GH-16101: Segfault in ldap_list(), ldap_read(), and ldap_search() when LDAPs array is not a list
--EXTENSIONS--
ldap
--FILE--
<?php

/* We are assuming 3333 is not connectable */
$ldap = ldap_connect('ldap://127.0.0.1:3333');
$valid_dn = "cn=userA,something";
$valid_filter = "";

$ldaps_dict = [
"hello" => $ldap,
"world" => $ldap,
];
try {
var_dump(ldap_list($ldaps_dict, $valid_dn, $valid_filter));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
ValueError: ldap_list(): Argument #1 ($ldap) must be a list

0 comments on commit 44f48dc

Please sign in to comment.