]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: tools: Crash if inet_ntop fails due to ENOSPC in sa2str
authorTim Duesterhus <tim@bastelstu.be>
Mon, 23 May 2022 07:30:49 +0000 (09:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 23 May 2022 07:39:32 +0000 (09:39 +0200)
This is impossible, because we pass a destination buffer that is appropriately
sized to hold an IPv6 address.

This is related to GitHub issue #1599.

src/tools.c

index 79d1d5c9b193bff0790b17008cff6627cee0a580..4ecbdc4d71da71a14f22e77d8490610a2011a2e8 100644 (file)
@@ -1375,7 +1375,10 @@ char * sa2str(const struct sockaddr_storage *addr, int port, int map_ports)
        default:
                return NULL;
        }
-       inet_ntop(addr->ss_family, ptr, buffer, sizeof(buffer));
+       if (inet_ntop(addr->ss_family, ptr, buffer, sizeof(buffer)) == NULL) {
+               BUG_ON(errno == ENOSPC);
+               return NULL;
+       }
        if (map_ports)
                return memprintf(&out, "%s:%+d", buffer, port);
        else