From 02f4ffd2daefdd4c1e630a8a6c49f006a5546318 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Thu, 29 Oct 2020 00:53:18 +0100 Subject: [PATCH] fix(ldap): pagination for PHP 7.4 & 8.0 After PR #38392 there is a little issue in the Symfony code base that occurs only for PHP 7.4 and PHP 8.0. This is related to issue #38874 --- .../Component/Ldap/Adapter/ExtLdap/Query.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php index 151e47881143f..17775e3340b84 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php @@ -174,8 +174,7 @@ public function getResources(): array private function resetPagination() { $con = $this->connection->getResource(); - $this->controlPagedResultResponse($con, 0, ''); - $this->serverctrls = []; + $this->controlPagedResultResponse($con, null, ''); // This is a workaround for a bit of a bug in the above invocation // of ldap_control_paged_result. Instead of indicating to extldap that @@ -226,16 +225,23 @@ private function controlPagedResult($con, int $pageSize, string $cookie): bool /** * Retrieve LDAP pagination cookie. * - * @param resource $con - * @param resource $result + * @param resource $con + * @param resource|null $result */ private function controlPagedResultResponse($con, $result, string $cookie = ''): string { + $this->serverctrls = []; + if (\PHP_VERSION_ID < 70300) { ldap_control_paged_result_response($con, $result, $cookie); return $cookie; } + + if (null === $result) { + return ''; + } + ldap_parse_result($con, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls); return $controls[\LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';