]> granicus.if.org Git - pgbouncer/commitdiff
log_socket_prefix: avoid corrupt hosts in log
authorMarko Kreen <markokr@gmail.com>
Fri, 21 Oct 2011 11:30:46 +0000 (14:30 +0300)
committerMarko Kreen <markokr@gmail.com>
Fri, 21 Oct 2011 11:30:46 +0000 (14:30 +0300)
- increase host name buffer and clear it, seems inet_ntop is allowed
  to not zero-terminate...
- detect failed conversion

src/util.c

index 9d136f8709c328b34ef49f1f90ffe2f865bc0429..025cc5a4570680c4e6beb64096ebd17dc1ec7964 100644 (file)
@@ -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);