about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-05-11 11:32:16 +0200
committerFlorian Weimer <fweimer@redhat.com>2018-01-04 11:45:25 +0100
commitd3f885d7ea9e8a8aa142ccd69e6f85c1a4a70033 (patch)
tree0e8fc1a0e7d6b3df41890db3703a9f98eeb1e8a3
parentd8bda0713bd898e9f962cee6d4e3d225441ef5a3 (diff)
downloadglibc-d3f885d7ea9e8a8aa142ccd69e6f85c1a4a70033.tar.gz
glibc-d3f885d7ea9e8a8aa142ccd69e6f85c1a4a70033.tar.xz
glibc-d3f885d7ea9e8a8aa142ccd69e6f85c1a4a70033.zip
support_format_addrinfo: Fix flags and canonname formatting
The address family splitting via format_ai_family made unpredictable
the place where the canonname field was printed.  This commit adjusts
the implementation so that the ai_flags is checked for consistency
across the list, and ai_canonname must only be present on the first
list element.

Tests for AI_CANONNAME are added to resolv/tst-resolv-basic.

(cherry picked from commit 8ec69bb7ecf3ca5edde5b7d9d7d5d3a5f8b6c405)
-rw-r--r--ChangeLog16
-rw-r--r--resolv/tst-resolv-basic.c71
2 files changed, 83 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 7717722465..473f5fddde 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2017-05-11  Florian Weimer  <fweimer@redhat.com>
+
+	* support/support_format_addrinfo.c (format_ai_flags_1): Renamed
+	from format_ai_flags.
+	(format_ai_flags): New function.  Incorporate flag formatting code
+	from format_ai_one.
+	(format_ai_canonname): New function.
+	(format_ai_one): Remove flags parameter.
+	(format_ai_family): Likewise.
+	(support_format_addrinfo): Call format_ai_flags,
+	format_ai_canonname.
+	* resolv/tst-resolv-basic.c (check_ai_hints): Extracted from
+	check_ai.
+	(check_ai): Call check_ai_hints.
+	(do_test): Add AI_CANONNAME tests.
+
 2017-04-13  Florian Weimer  <fweimer@redhat.com>
 
 	[BZ #21359]
diff --git a/resolv/tst-resolv-basic.c b/resolv/tst-resolv-basic.c
index f2b1fc7490..92f912beed 100644
--- a/resolv/tst-resolv-basic.c
+++ b/resolv/tst-resolv-basic.c
@@ -182,12 +182,12 @@ check_h (const char *name, int family, const char *expected)
 }
 
 static void
-check_ai (const char *name, const char *service,
-          int family, const char *expected)
+check_ai_hints (const char *name, const char *service,
+                struct addrinfo hints, const char *expected)
 {
-  struct addrinfo hints = {.ai_family = family};
   struct addrinfo *ai;
-  char *query = xasprintf ("%s:%s [%d]", name, service, family);
+  char *query = xasprintf ("%s:%s [%d]/0x%x", name, service,
+                           hints.ai_family, hints.ai_flags);
   int ret = getaddrinfo (name, service, &hints, &ai);
   check_addrinfo (query, ai, ret, expected);
   if (ret == 0)
@@ -195,6 +195,15 @@ check_ai (const char *name, const char *service,
   free (query);
 }
 
+static void
+check_ai (const char *name, const char *service,
+          int family, const char *expected)
+{
+  return check_ai_hints (name, service,
+                         (struct addrinfo) { .ai_family = family, },
+                         expected);
+}
+
 static int
 do_test (void)
 {
@@ -229,6 +238,17 @@ do_test (void)
             "address: STREAM/TCP 2001:db8::1 80\n"
             "address: DGRAM/UDP 2001:db8::1 80\n"
             "address: RAW/IP 2001:db8::1 80\n");
+  check_ai_hints ("www.example", "80",
+                  (struct addrinfo) { .ai_family = AF_UNSPEC,
+                      .ai_flags = AI_CANONNAME, },
+                  "flags: AI_CANONNAME\n"
+                  "canonname: www.example\n"
+                  "address: STREAM/TCP 192.0.2.17 80\n"
+                  "address: DGRAM/UDP 192.0.2.17 80\n"
+                  "address: RAW/IP 192.0.2.17 80\n"
+                  "address: STREAM/TCP 2001:db8::1 80\n"
+                  "address: DGRAM/UDP 2001:db8::1 80\n"
+                  "address: RAW/IP 2001:db8::1 80\n");
   check_ai ("alias.example", "80", AF_UNSPEC,
             "address: STREAM/TCP 192.0.2.18 80\n"
             "address: DGRAM/UDP 192.0.2.18 80\n"
@@ -236,6 +256,17 @@ do_test (void)
             "address: STREAM/TCP 2001:db8::2 80\n"
             "address: DGRAM/UDP 2001:db8::2 80\n"
             "address: RAW/IP 2001:db8::2 80\n");
+  check_ai_hints ("alias.example", "80",
+                  (struct addrinfo) { .ai_family = AF_UNSPEC,
+                      .ai_flags = AI_CANONNAME, },
+                  "flags: AI_CANONNAME\n"
+                  "canonname: www.example\n"
+                  "address: STREAM/TCP 192.0.2.18 80\n"
+                  "address: DGRAM/UDP 192.0.2.18 80\n"
+                  "address: RAW/IP 192.0.2.18 80\n"
+                  "address: STREAM/TCP 2001:db8::2 80\n"
+                  "address: DGRAM/UDP 2001:db8::2 80\n"
+                  "address: RAW/IP 2001:db8::2 80\n");
   check_ai (LONG_NAME, "80", AF_UNSPEC,
             "address: STREAM/TCP 192.0.2.20 80\n"
             "address: DGRAM/UDP 192.0.2.20 80\n"
@@ -247,10 +278,26 @@ do_test (void)
             "address: STREAM/TCP 192.0.2.17 80\n"
             "address: DGRAM/UDP 192.0.2.17 80\n"
             "address: RAW/IP 192.0.2.17 80\n");
+  check_ai_hints ("www.example", "80",
+                  (struct addrinfo) { .ai_family = AF_INET,
+                      .ai_flags = AI_CANONNAME, },
+                  "flags: AI_CANONNAME\n"
+                  "canonname: www.example\n"
+                  "address: STREAM/TCP 192.0.2.17 80\n"
+                  "address: DGRAM/UDP 192.0.2.17 80\n"
+                  "address: RAW/IP 192.0.2.17 80\n");
   check_ai ("alias.example", "80", AF_INET,
             "address: STREAM/TCP 192.0.2.18 80\n"
             "address: DGRAM/UDP 192.0.2.18 80\n"
             "address: RAW/IP 192.0.2.18 80\n");
+  check_ai_hints ("alias.example", "80",
+                  (struct addrinfo) { .ai_family = AF_INET,
+                      .ai_flags = AI_CANONNAME, },
+                  "flags: AI_CANONNAME\n"
+                  "canonname: www.example\n"
+                  "address: STREAM/TCP 192.0.2.18 80\n"
+                  "address: DGRAM/UDP 192.0.2.18 80\n"
+                  "address: RAW/IP 192.0.2.18 80\n");
   check_ai (LONG_NAME, "80", AF_INET,
             "address: STREAM/TCP 192.0.2.20 80\n"
             "address: DGRAM/UDP 192.0.2.20 80\n"
@@ -259,10 +306,26 @@ do_test (void)
             "address: STREAM/TCP 2001:db8::1 80\n"
             "address: DGRAM/UDP 2001:db8::1 80\n"
             "address: RAW/IP 2001:db8::1 80\n");
+  check_ai_hints ("www.example", "80",
+                  (struct addrinfo) { .ai_family = AF_INET6,
+                      .ai_flags = AI_CANONNAME, },
+                  "flags: AI_CANONNAME\n"
+                  "canonname: www.example\n"
+                  "address: STREAM/TCP 2001:db8::1 80\n"
+                  "address: DGRAM/UDP 2001:db8::1 80\n"
+                  "address: RAW/IP 2001:db8::1 80\n");
   check_ai ("alias.example", "80", AF_INET6,
             "address: STREAM/TCP 2001:db8::2 80\n"
             "address: DGRAM/UDP 2001:db8::2 80\n"
             "address: RAW/IP 2001:db8::2 80\n");
+  check_ai_hints ("alias.example", "80",
+                  (struct addrinfo) { .ai_family = AF_INET6,
+                      .ai_flags = AI_CANONNAME, },
+                  "flags: AI_CANONNAME\n"
+                  "canonname: www.example\n"
+                  "address: STREAM/TCP 2001:db8::2 80\n"
+                  "address: DGRAM/UDP 2001:db8::2 80\n"
+                  "address: RAW/IP 2001:db8::2 80\n");
   check_ai (LONG_NAME, "80", AF_INET6,
             "address: STREAM/TCP 2001:db8::4 80\n"
             "address: DGRAM/UDP 2001:db8::4 80\n"