From 59b8f4ff840aaaf1f06c348d26da64cc75f87eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rok=20Pape=C5=BE=2C=20ARNES?= Date: Wed, 16 Oct 2013 15:57:55 -0600 Subject: [PATCH] ipv6 loopbacks fix for GNU libc getaddrinfo() On any OS with a properly implemented getaddrinfo() this change is a no-op. Passing NULL for the hint is supposed to be the same as an addrinfo structure with all fields set to 0. There is no need to set ai_family to AF_UNSPEC because that value is already 0. GNU libc doesn't follow standard behaviour. Quoting from http://man7.org/linux/man-pages/man3/getaddrinfo.3.html : "Specifying hints as NULL is equivalent to setting ai_socktype and ai_protocol to 0; ai_family to AF_UNSPEC; and ai_flags to (AI_V4MAPPED | AI_ADDRCONFIG). (POSIX specifies different defaults for ai_flags; see NOTES.)" The NOTES section says: "According to POSIX.1-2001, specifying hints as NULL should cause ai_flags to be assumed as 0. The GNU C library instead assumes a value of (AI_V4MAPPED | AI_ADDRCONFIG) for this case, since this value is considered an improvement on the specification." The patch makes sure that krb5_parse_address works consistently on both GNU libc and systems that follow POSIX.1-2001 to the letter. Some incorrect Fedora 17 patches managed to break IPv6 connectivity and were later backed out (see discussion at https://bugzilla.redhat.com/808147). This patch resolves the incompatibility. Signed-off-by: Ken Dreyer --- lib/krb5/addr_families.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/krb5/addr_families.c b/lib/krb5/addr_families.c index 10b102440..7ac0fa93f 100644 --- a/lib/krb5/addr_families.c +++ b/lib/krb5/addr_families.c @@ -1161,6 +1161,7 @@ krb5_parse_address(krb5_context context, { int i, n; struct addrinfo *ai, *a; + struct addrinfo hint; int error; int save_errno; @@ -1180,7 +1181,10 @@ krb5_parse_address(krb5_context context, } } - error = getaddrinfo (string, NULL, NULL, &ai); + /* if not parsed as numeric address, do a name lookup */ + memset(&hint, 0, sizeof(hint)); + hint.ai_family = AF_UNSPEC; + error = getaddrinfo (string, NULL, &hint, &ai); if (error) { krb5_error_code ret2; save_errno = errno;