Skip to content

Commit 0bcdab5

Browse files
committed
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: Michael Paquier <michael.paquier@gmail.com>
1 parent 18d431b commit 0bcdab5

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/backend/libpq/auth.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,8 @@ CheckLDAPAuth(Port *port)
20132013
{
20142014
ereport(LOG,
20152015
(errmsg("could not perform initial LDAP bind for ldapbinddn \"%s\" on server \"%s\": %s",
2016-
port->hba->ldapbinddn, port->hba->ldapserver, ldap_err2string(r))));
2016+
port->hba->ldapbinddn ? port->hba->ldapbinddn : "",
2017+
port->hba->ldapserver, ldap_err2string(r))));
20172018
return STATUS_ERROR;
20182019
}
20192020

src/backend/libpq/hba.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,9 +1453,11 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline, int line_num)
14531453
return false;
14541454
}
14551455

1456-
hbaline->ldapserver = pstrdup(urldata->lud_host);
1456+
if (urldata->lud_host)
1457+
hbaline->ldapserver = pstrdup(urldata->lud_host);
14571458
hbaline->ldapport = urldata->lud_port;
1458-
hbaline->ldapbasedn = pstrdup(urldata->lud_dn);
1459+
if (urldata->lud_dn)
1460+
hbaline->ldapbasedn = pstrdup(urldata->lud_dn);
14591461

14601462
if (urldata->lud_attrs)
14611463
hbaline->ldapsearchattribute = pstrdup(urldata->lud_attrs[0]); /* only use first one */

0 commit comments

Comments
 (0)