From 93146199fd91365fc0c10d8a397f6c2dd102a04a Mon Sep 17 00:00:00 2001 From: ahgamut <41098605+ahgamut@users.noreply.github.com> Date: Tue, 6 Jul 2021 22:36:37 +0530 Subject: [PATCH] getaddrinfo AI_PASSIVE memory error when getaddrinfo is passed name = NULL and AI_PASSIVE in hints->ai_flags, it was setting the s_addr value to INADDR_ANY but *not* returning the addrinfo pointer via *res = ai. This caused a free(NULL) memory error when the caller tried to free res, because the caller expects res to be a valid pointer to an struct addrinfo. Fix was to assign *res = ai before returning in the AI_PASSIVE case. --- libc/dns/getaddrinfo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/dns/getaddrinfo.c b/libc/dns/getaddrinfo.c index 8da6160b2..215e6eb91 100644 --- a/libc/dns/getaddrinfo.c +++ b/libc/dns/getaddrinfo.c @@ -59,6 +59,7 @@ int getaddrinfo(const char *name, const char *service, (hints && (hints->ai_flags & AI_PASSIVE) == AI_PASSIVE) ? INADDR_ANY : INADDR_LOOPBACK; + *res = ai; return 0; } if (inet_pton(AF_INET, name, &ai->ai_addr4->sin_addr.s_addr) == 1) {