Skip to content

Commit 99e9733

Browse files
bug #47547 [Ldap] Do not run ldap_set_option on failed connection (tatankat)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Ldap] Do not run ldap_set_option on failed connection | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | License | MIT ldap_set_option should only be called on null (first time setOption is run) or on an LDAP\Connection instance. When ldap_connect fails, it returns a boolean. ldap_set_option fails on this, which results in an early TypeError instead of the LdapException with the real issue: 'Could not connect to Ldap server'. So, the result of ldap_connect should be checked earlier. Commits ------- 8f4f2b1 [Ldap] Do not run ldap_set_option on failed connection
2 parents 9fd0eef + 8f4f2b1 commit 99e9733

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,18 @@ private function connect()
159159
}
160160
}
161161

162-
$this->connection = ldap_connect($this->config['connection_string']);
162+
if (false === $connection = ldap_connect($this->config['connection_string'])) {
163+
throw new LdapException('Invalid connection string: '.$this->config['connection_string']);
164+
} else {
165+
$this->connection = $connection;
166+
}
163167

164168
foreach ($this->config['options'] as $name => $value) {
165169
if (!\in_array(ConnectionOptions::getOption($name), self::PRECONNECT_OPTIONS, true)) {
166170
$this->setOption($name, $value);
167171
}
168172
}
169173

170-
if (false === $this->connection) {
171-
throw new LdapException('Could not connect to Ldap server: '.ldap_error($this->connection));
172-
}
173-
174174
if ('tls' === $this->config['encryption'] && false === @ldap_start_tls($this->connection)) {
175175
throw new LdapException('Could not initiate TLS connection: '.ldap_error($this->connection));
176176
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy