From a99dd00a9de35504fa0133c8e2ede72d275d976b Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Fri, 21 Oct 2011 14:30:46 +0300 Subject: [PATCH] log_socket_prefix: avoid corrupt hosts in log - increase host name buffer and clear it, seems inet_ntop is allowed to not zero-terminate... - detect failed conversion --- src/util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/util.c b/src/util.c index 9d136f8..025cc5a 100644 --- a/src/util.c +++ b/src/util.c @@ -28,8 +28,8 @@ int log_socket_prefix(enum LogLevel lev, void *ctx, char *dst, unsigned int dstlen) { const struct PgSocket *sock = ctx; - char *user, *db, *host; - char host6[INET6_ADDRSTRLEN]; + const char *user, *db, *host; + char host6[PGADDR_BUF]; int port; /* no prefix */ @@ -42,8 +42,10 @@ int log_socket_prefix(enum LogLevel lev, void *ctx, char *dst, unsigned int dstl if (pga_is_unix(&sock->remote_addr)) { host = "unix"; } else { - pga_ntop(&sock->remote_addr, host6, INET6_ADDRSTRLEN); - host = host6; + memset(host6, 0, sizeof(host6)); + host = pga_ntop(&sock->remote_addr, host6, sizeof(host6)); + if (!host) + host = "(ntop-err)"; } port = pga_port(&sock->remote_addr); -- 2.40.0