Skip to content

Commit 24986c9

Browse files
committed
Change libpq's internal uses of PQhost() to inspect host field directly.
Commit 1944cdc changed PQhost() to return the hostaddr value when that is specified and host isn't. This is a good idea in general, but fe-auth.c and related files contain PQhost() calls for which it isn't. Specifically, when we compare SSL certificates or other server identity information to the host field, we do not want to use hostaddr instead; that's not what's documented, that's not what happened pre-v10, and it doesn't seem like a good idea. Instead, we can just look at connhost[].host directly. This does what we want in v10 and up; in particular, if neither host nor hostaddr were given, the host field will be replaced with the default host name. That seems useful, and it's likely the reason that these places were coded to call PQhost() originally (since pre-v10, the stored field was not replaced with the default). Back-patch to v10, as 1944cdc (just) was. Discussion: https://postgr.es/m/23287.1533227021@sss.pgh.pa.us
1 parent 85c9d34 commit 24986c9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/interfaces/libpq/fe-auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pg_GSS_startup(PGconn *conn, int payloadlen)
199199
min_stat;
200200
int maxlen;
201201
gss_buffer_desc temp_gbuf;
202-
char *host = PQhost(conn);
202+
char *host = conn->connhost[conn->whichhost].host;
203203

204204
if (!(host && host[0] != '\0'))
205205
{
@@ -414,7 +414,7 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
414414
{
415415
SECURITY_STATUS r;
416416
TimeStamp expire;
417-
char *host = PQhost(conn);
417+
char *host = conn->connhost[conn->whichhost].host;
418418

419419
if (conn->sspictx)
420420
{

src/interfaces/libpq/fe-secure-common.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,17 @@ pq_verify_peer_name_matches_certificate_name(PGconn *conn,
8888
{
8989
char *name;
9090
int result;
91-
char *host = PQhost(conn);
91+
char *host = conn->connhost[conn->whichhost].host;
9292

9393
*store_name = NULL;
9494

95+
if (!(host && host[0] != '\0'))
96+
{
97+
printfPQExpBuffer(&conn->errorMessage,
98+
libpq_gettext("host name must be specified\n"));
99+
return -1;
100+
}
101+
95102
/*
96103
* There is no guarantee the string returned from the certificate is
97104
* NULL-terminated, so make a copy that is.
@@ -145,7 +152,7 @@ pq_verify_peer_name_matches_certificate_name(PGconn *conn,
145152
bool
146153
pq_verify_peer_name_matches_certificate(PGconn *conn)
147154
{
148-
char *host = PQhost(conn);
155+
char *host = conn->connhost[conn->whichhost].host;
149156
int rc;
150157
int names_examined = 0;
151158
char *first_name = NULL;

0 commit comments

Comments
 (0)