From 6d45c0fe89e6de7d35a991051ec7f9feaaaf3729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Tue, 7 Jun 2022 17:39:04 +0200 Subject: inet: gethostid: only accept v4 addresses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getaddrinfo() returns addresses from, at least, ip(7) and ipv6(7), but _addr() always uses sin_addr from struct sockaddr_in; we're saved from wild unsoundness (or incompatibility) by virtue of struct sockaddr_in6 having an always-0 u32 sin6_flowinfo at the same offset, so we end up returning 0 anyway, but in a round-about and definitely unintended way Instead, limit the request to AF_INET, and fall through to the end early, returning the default id=0 Signed-off-by: Ahelenia ZiemiaƄska --- libc/inet/hostid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc/inet/hostid.c b/libc/inet/hostid.c index 4ddfbd123..5977ada25 100644 --- a/libc/inet/hostid.c +++ b/libc/inet/hostid.c @@ -61,8 +61,7 @@ long int gethostid(void) * Mitch */ if (gethostname(host, HOST_NAME_MAX) >= 0 && *host) { - struct addrinfo hints, *results, *addr; - memset(&hints, 0, sizeof(struct addrinfo)); + struct addrinfo hints = {.ai_family = AF_INET}, *results, *addr; if (!getaddrinfo(host, NULL, &hints, &results)) { for (addr = results; addr; addr = results->ai_next) { /* Just so it doesn't look exactly like the -- cgit v1.2.3