Skip to content

ldap_search fails when $attributes contains a non-packed array with numerical keys #17704

Closed
@7u83

Description

@7u83

Description

The following code:

<?php
$ldapHost = "<yourhost>";  
$baseDN = "<yourbasedn>";

$linkID = ldap_connect($ldapHost);
if (!$linkID) { die("error connecting to host."); }
ldap_set_option($linkID, LDAP_OPT_PROTOCOL_VERSION, 3);
if (!ldap_bind($linkID)) { die("Error binding" . ldap_error($linkID)); }
$sizelimit=0; $timelimit=0; $deref=true; $attrsonly=false;
$filter = "uid=*";

$attributes = array ("uid","cn");

// force a non-packed array 
$attributes['x']="x"; unset($attributes['x']);

$searchResult = ldap_search($linkID, $baseDN, $filter, $attributes, $attrsonly,
                        $sizelimit, $timelimit, $deref
);
if (!$searchResult ) {
    die("Error: " . ldap_error($linkID)."\n");
}
echo "ldap_search was successsful\n";

Resulted in this output:

PHP Warning:  ldap_search(): Argument #4 ($attributes) must be an array with numeric keys in test.php on line 16
Error: Success

But I expected this output instead:

ldap_search was successsful

Function php_ldap_is_numerically_indexed_array has to return true here:
https://github.com/php/php-src/blob/PHP-8.3.16/ext/ldap/ldap.c#L251
https://github.com/php/php-src/blob/PHP-8.3.17/ext/ldap/ldap.c#L251
https://github.com/php/php-src/blob/PHP-8.4.3/ext/ldap/ldap.c#L250
https://github.com/php/php-src/blob/PHP-8.4.4/ext/ldap/ldap.c#L250

PHP Version

PHP 8.3.16, PHP 8.3.17, PHP 8.4.3, PHP 8.4.4

Operating System

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions