Commit 0c98d0dd authored by Peter Eisentraut's avatar Peter Eisentraut

Fix some null pointer dereferences in LDAP auth code

An LDAP URL without a host name such as "ldap://" or without a base DN
such as "ldap://localhost" would cause a crash when reading pg_hba.conf.

If no binddn is configured, an error message might end up trying to print a
null pointer, which could crash on some platforms.

Author: Thomas Munro <thomas.munro@enterprisedb.com>
Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
parent 0e1539ba
...@@ -2520,7 +2520,8 @@ CheckLDAPAuth(Port *port) ...@@ -2520,7 +2520,8 @@ CheckLDAPAuth(Port *port)
{ {
ereport(LOG, ereport(LOG,
(errmsg("could not perform initial LDAP bind for ldapbinddn \"%s\" on server \"%s\": %s", (errmsg("could not perform initial LDAP bind for ldapbinddn \"%s\" on server \"%s\": %s",
port->hba->ldapbinddn, port->hba->ldapserver, port->hba->ldapbinddn ? port->hba->ldapbinddn : "",
port->hba->ldapserver,
ldap_err2string(r)), ldap_err2string(r)),
errdetail_for_ldap(ldap))); errdetail_for_ldap(ldap)));
ldap_unbind(ldap); ldap_unbind(ldap);
......
...@@ -1739,8 +1739,10 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline, ...@@ -1739,8 +1739,10 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline,
return false; return false;
} }
if (urldata->lud_host)
hbaline->ldapserver = pstrdup(urldata->lud_host); hbaline->ldapserver = pstrdup(urldata->lud_host);
hbaline->ldapport = urldata->lud_port; hbaline->ldapport = urldata->lud_port;
if (urldata->lud_dn)
hbaline->ldapbasedn = pstrdup(urldata->lud_dn); hbaline->ldapbasedn = pstrdup(urldata->lud_dn);
if (urldata->lud_attrs) if (urldata->lud_attrs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment