Skip to content

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

Closed

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

Activity

  1. devnexen commented on Feb 5, 2025

    @devnexen
    Member

    can't check for now but @nielsdos do you think it s because of the nature of the loop here ?

  2. ndossche commented on Feb 5, 2025

    @ndossche
    Member

    No, just looks like an incorrect backport in 26f3bec
    I can fix it later today.

  3. self-assigned this
    on Feb 5, 2025
  4. added theissue type on Feb 5, 2025
  5. added a commit that references this issue on Feb 5, 2025
    7ac8491
  6. added 2 commits that reference this issue on Feb 6, 2025
    2fb88b2
    e3a2306
  7. added a commit that references this issue on Feb 6, 2025
    459fc9d
  8. ndossche commented on Feb 6, 2025

    @ndossche
    Member

    The fix is now merged, and will be available in the next release of 8.3 and 8.4. I've credited OP too because the diagnosis of the problem was right and the solution as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions