postgres.git / summary / log / commit / refs

commit    6efc30167188f2adea8741dc1b69f6536b2c9b44
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Fri Aug 03 16:12:10 2018 +0000
First released in: 12.0, 10.5, 11.0

    Change libpq's internal uses of PQhost() to inspect host field directly.
    
    Commit 1944cdc98 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 1944cdc98 (just) was.
    
    Discussion: https://postgr.es/m/23287.1533227021@sss.pgh.pa.us


src/interfaces/libpq/fe-auth.c | 4 ++-- src/interfaces/libpq/fe-secure-common.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 3b2073a47fe..09012c562d0 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -199,7 +199,7 @@ pg_GSS_startup(PGconn *conn, int payloadlen) min_stat; int maxlen; gss_buffer_desc temp_gbuf; - char *host = PQhost(conn); + char *host = conn->connhost[conn->whichhost].host; if (!(host && host[0] != '\0')) { @@ -414,7 +414,7 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen) { SECURITY_STATUS r; TimeStamp expire; - char *host = PQhost(conn); + char *host = conn->connhost[conn->whichhost].host; if (conn->sspictx) { diff --git a/src/interfaces/libpq/fe-secure-common.c b/src/interfaces/libpq/fe-secure-common.c index 40203f3b642..b3f580f5950 100644 --- a/src/interfaces/libpq/fe-secure-common.c +++ b/src/interfaces/libpq/fe-secure-common.c @@ -88,10 +88,17 @@ pq_verify_peer_name_matches_certificate_name(PGconn *conn, { char *name; int result; - char *host = PQhost(conn); + char *host = conn->connhost[conn->whichhost].host; *store_name = NULL; + if (!(host && host[0] != '\0')) + { + printfPQExpBuffer(&conn->errorMessage, + libpq_gettext("host name must be specified\n")); + return -1; + } + /* * There is no guarantee the string returned from the certificate is * NULL-terminated, so make a copy that is. @@ -145,7 +152,7 @@ pq_verify_peer_name_matches_certificate_name(PGconn *conn, bool pq_verify_peer_name_matches_certificate(PGconn *conn) { - char *host = PQhost(conn); + char *host = conn->connhost[conn->whichhost].host; int rc; int names_examined = 0; char *first_name = NULL; [parent: dac7fe13bbf1]