Bug #78450 [Ver]: ldap_parse_result() sets size of LDAP Controll LDAP_CONTROL_PAGEDRESULTS to 0

From: Date: Tue, 23 Mar 2021 13:37:00 +0000
Subject: Bug #78450 [Ver]: ldap_parse_result() sets size of LDAP Controll LDAP_CONTROL_PAGEDRESULTS to 0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232929@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78450&edit=1 ID: 78450 Updated by: cmb@php.net Reported by: kagome at opentrash dot com Summary: ldap_parse_result() sets size of LDAP Controll LDAP_CONTROL_PAGEDRESULTS to 0 Status: Verified Type: Bug Package: LDAP related Operating System: Windows 10 / Server 2016 PHP Version: 7.3.8 Block user comment: N Private report: N New Comment: Disregard my comment above; I totally misread the code. Previous Comments: ------------------------------------------------------------------------ [2021-03-22 11:04:15] mcmic@php.net No, your code is not the same as the example, you use the same array for request and response, and thus you erase your request control with the response control. In the RFC for paged control: «In the control returned to the client, the size MAY be set to the server's estimate of the total number of entries in the entire result set. Servers that cannot provide such an estimate MAY set this size to zero (0).» So it is expected that size may be 0 in the response control, and it will NOT be the page size anyway. ------------------------------------------------------------------------ [2019-08-24 13:03:14] cmb@php.net It seems to me that the implementation of ldap_parse_result() is severly broken, since it confuses zvals with completely unrelated types. ------------------------------------------------------------------------ [2019-08-24 11:38:38] kagome at opentrash dot com Description: ------------ ldap_parse_result() sets "size" of LDAP Control LDAP_CONTROL_PAGEDRESULTS to 0 instead of keeping the old value. Test script: --------------- Basicly the Code is the same as here: https://www.php.net/manual/en/function.ldap-control-paged-result.php $searchValue = ldap_escape("P", null, LDAP_ESCAPE_FILTER); // Looking for Computers that has P in name (in my Case more than 2000) // $ldapconn is a valid link identifier for a directory server // $ldaptree is a valid ldaptree $serverctrls = array(); // I need paged results because the Active Directory shows only 1000 Entries max. $serverctrls[LDAP_CONTROL_PAGEDRESULTS] = array("oid" => LDAP_CONTROL_PAGEDRESULTS, "value" => array("size" => 999, "cookie" => "")); $resultData = array(); // Array to store all results do { var_dump($serverctrls); $result = ldap_search($ldapconn, $ldaptree, "(&(objectClass=person)(objectClass=user)(objectClass=organizationalPerson)(objectClass=computer)(|(samaccountname=*".$searchValue."*)(name=*".$searchValue."*)))", array("*"), // default Parameter https://www.php.net/manual/en/function.ldap-search.php 0, // default Parameter -1, // default Parameter -1, // default Parameter LDAP_DEREF_NEVER, // default Parameter $serverctrls); $errcode = $dn = $errmsg = $refs = null; ldap_parse_result($this->ldapconn, $result, $errcode, $dn, $errmsg, $refs ,$serverctrls); // this will update my LDAP Controlls $serverctrls with Cookie infos $data = ldap_get_entries($this->ldapconn, $result); for ($i=0; $i<$data["count"]; $i++) { array_push($resultData, $data[$i]); // push all single Entries to a big array } }while($serverctrls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] !== null && $serverctrls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] != ''); return $resultData; Expected result: ---------------- Check the var_dump line: On first run in do-Loop I expect: array(1) { ["1.2.840.113556.1.4.319"]=> array(2) { ["oid"]=> string(22) "1.2.840.113556.1.4.319" ["value"]=> array(2) { ["size"]=> int(999) ["cookie"]=> string(0) "" } } } on the second run in do-Loop I expect: array(1) { ["1.2.840.113556.1.4.319"]=> array(2) { ["oid"]=> string(22) "1.2.840.113556.1.4.319" ["value"]=> array(2) { ["size"]=> int(999) ["cookie"]=> string(0) "CookieContentInformation-bla" } } } So Cookie Information is filled. Actual result: -------------- What I get on second run in do-Loop is: array(1) { ["1.2.840.113556.1.4.319"]=> array(2) { ["oid"]=> string(22) "1.2.840.113556.1.4.319" ["value"]=> array(2) { ["size"]=> int(0) ["cookie"]=> string(0) "CookieContentInformation-bla" } } } Why is "size"-key now 0? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78450&edit=1

« previous php.bugs (#232929) next »