summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-06-21 17:03:38 -0400
committerAndreas Schwab <schwab@redhat.com>2011-06-22 10:49:40 +0200
commit0e779ef2a9fcfd13f5243224c82894ba797ecec3 (patch)
tree41355d9d55bf26be780e8dec2d2a28bc4abcaab1
parent5babac1535735419921ca9edbf5f6c96a40296da (diff)
downloadglibc-0e779ef2a9fcfd13f5243224c82894ba797ecec3.tar.gz
Fix IPv6-only lookups through getaddrinfo
A recent patch introduced a problem where IPv6 lookups happily returned IPv4 addresses. (cherry picked from commit c0244a9dedce43a4b950d91451b16a7cf5408476)
-rw-r--r--ChangeLog6
-rw-r--r--sysdeps/posix/getaddrinfo.c34
2 files changed, 37 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index c29470ac74..47a9fbbb57 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-06-21 Ulrich Drepper <drepper@gmail.com>
+
+ [BZ #12885]
+ * sysdeps/posix/getaddrinfo.c (gaih_inet): When looking up only IPv6
+ addresses using gethostbyname4_r ignore IPv4 addresses.
+
2011-06-15 Ulrich Drepper <drepper@gmail.com>
* resolv/res_send.c (__libc_res_nsend): Fix typos in last patch. We
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 469abe22de..abd8551074 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -881,16 +881,44 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
}
- no_inet6_data = no_data;
-
if (status == NSS_STATUS_SUCCESS)
{
+ assert (!no_data);
+ no_data = 1;
+
if ((req->ai_flags & AI_CANONNAME) != 0 && canon == NULL)
canon = (*pat)->name;
while (*pat != NULL)
- pat = &((*pat)->next);
+ {
+ if ((*pat)->family == AF_INET
+ && req->ai_family == AF_INET6
+ && (req->ai_flags & AI_V4MAPPED) != 0)
+ {
+ uint32_t *pataddr = (*pat)->addr;
+ (*pat)->family = AF_INET6;
+ pataddr[3] = pataddr[0];
+ pataddr[2] = htonl (0xffff);
+ pataddr[1] = 0;
+ pataddr[0] = 0;
+ pat = &((*pat)->next);
+ no_data = 0;
+ }
+ else if ((*pat)->family == AF_UNSPEC
+ || (*pat)->family == req->ai_family)
+ {
+ pat = &((*pat)->next);
+
+ no_data = 0;
+ if (req->ai_family == AF_INET6)
+ got_ipv6 = true;
+ }
+ else
+ *pat = ((*pat)->next);
+ }
}
+
+ no_inet6_data = no_data;
}
else
{