Fix ares_getaddrinfo() numerical address fast path with AF_UNSPEC (#469)

The conversion of numeric IPv4 addresses in fake_addrinfo() is broken when
the family is AF_UNSPEC. The initial call to ares_inet_pton with AF_INET
will succeed, but the subsequent call using AF_INET6 will fail. This results
in the fake_addrinfo() fast path failing, and ares_getaddrinfo() making a
query when none should be required.

Resolve this by only attempting the call to ares_inet_pton with AF_INET6
if the initial call with AF_INET was unsuccessful.

Fix By: Ridge Kennedy (@ridgek)
pull/474/head
Ridge Kennedy 3 years ago committed by GitHub
parent 810c2322f9
commit 5aa25946e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/lib/ares_getaddrinfo.c

@ -326,7 +326,7 @@ static int fake_addrinfo(const char *name,
}
}
if (family == AF_INET6 || family == AF_UNSPEC)
if (!result && (family == AF_INET6 || family == AF_UNSPEC))
{
struct ares_in6_addr addr6;
result = ares_inet_pton(AF_INET6, name, &addr6) < 1 ? 0 : 1;

Loading…
Cancel
Save