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.
This commit is contained in:
ahgamut 2021-07-06 22:36:37 +05:30
parent 5cc93d31f8
commit 93146199fd

View file

@ -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) {