Skip to content

Commit 37e1cce

Browse files
committed
libpq: Fix SNI host handling
Fix handling of NULL host name (possibly by using hostaddr). It previously crashed. Also, we should look at connhost, not pghost, to handle multi-host specifications. Also remove an unnecessary SSL_CTX_free(). Reported-by: Jacob Champion <pchampion@vmware.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/504c276ab6eee000bb23d571ea9b0ced4250774e.camel@vmware.com
1 parent eab8195 commit 37e1cce

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,20 +1087,24 @@ initialize_SSL(PGconn *conn)
10871087
* Per RFC 6066, do not set it if the host is a literal IP address (IPv4
10881088
* or IPv6).
10891089
*/
1090-
if (conn->sslsni && conn->sslsni[0] &&
1091-
!(strspn(conn->pghost, "0123456789.") == strlen(conn->pghost) ||
1092-
strchr(conn->pghost, ':')))
1090+
if (conn->sslsni && conn->sslsni[0])
10931091
{
1094-
if (SSL_set_tlsext_host_name(conn->ssl, conn->pghost) != 1)
1092+
const char *host = conn->connhost[conn->whichhost].host;
1093+
1094+
if (host && host[0] &&
1095+
!(strspn(host, "0123456789.") == strlen(host) ||
1096+
strchr(host, ':')))
10951097
{
1096-
char *err = SSLerrmessage(ERR_get_error());
1098+
if (SSL_set_tlsext_host_name(conn->ssl, host) != 1)
1099+
{
1100+
char *err = SSLerrmessage(ERR_get_error());
10971101

1098-
appendPQExpBuffer(&conn->errorMessage,
1099-
libpq_gettext("could not set SSL Server Name Indication (SNI): %s\n"),
1100-
err);
1101-
SSLerrfree(err);
1102-
SSL_CTX_free(SSL_context);
1103-
return -1;
1102+
appendPQExpBuffer(&conn->errorMessage,
1103+
libpq_gettext("could not set SSL Server Name Indication (SNI): %s\n"),
1104+
err);
1105+
SSLerrfree(err);
1106+
return -1;
1107+
}
11041108
}
11051109
}
11061110

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