about summary refs log tree commit diff
path: root/support/support_format_dns_packet.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-03-15 12:57:12 +0100
committerFlorian Weimer <fweimer@redhat.com>2017-03-15 13:33:40 +0100
commitf889e73f603dcf90b4db6a2065104a78c1a0e94d (patch)
treee70508fa8cde79e40fcc965f28eea7fdfc11916a /support/support_format_dns_packet.c
parented7d6072f25f75b808b40c206371361f1313f342 (diff)
downloadglibc-f889e73f603dcf90b4db6a2065104a78c1a0e94d.tar.gz
glibc-f889e73f603dcf90b4db6a2065104a78c1a0e94d.tar.xz
glibc-f889e73f603dcf90b4db6a2065104a78c1a0e94d.zip
support_format_dns_packet: Fix CNAME and multiple RR handling
Before this change, the loop iterating over RRs in the answer
section stopped at the first CNAME record, never printing them.
The CNAME and PTR record contents was extracted from the wrong
buffer (whole packet instead RDATA).  This desynced the parsing
after the first CNAME or PTR record.

Also fix the AAAA record parsing by checking their sizes.
Diffstat (limited to 'support/support_format_dns_packet.c')
-rw-r--r--support/support_format_dns_packet.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/support/support_format_dns_packet.c b/support/support_format_dns_packet.c
index 21fe7e5c8d..2992c57971 100644
--- a/support/support_format_dns_packet.c
+++ b/support/support_format_dns_packet.c
@@ -174,7 +174,7 @@ support_format_dns_packet (const unsigned char *buffer, size_t length)
           goto out;
         }
       /* Skip non-matching record types.  */
-      if (rtype != qtype || rclass != qclass)
+      if ((rtype != qtype && rtype != T_CNAME) || rclass != qclass)
         continue;
       switch (rtype)
         {
@@ -186,22 +186,29 @@ support_format_dns_packet (const unsigned char *buffer, size_t length)
                        rdata.data[2],
                        rdata.data[3]);
           else
-            fprintf (mem.out, "error: A record of size %d: %s\n", rdlen, rname.name);
+            fprintf (mem.out, "error: A record of size %d: %s\n",
+                     rdlen, rname.name);
           break;
         case T_AAAA:
           {
-            char buf[100];
-            if (inet_ntop (AF_INET6, rdata.data, buf, sizeof (buf)) == NULL)
-              fprintf (mem.out, "error: AAAA record decoding failed: %m\n");
+            if (rdlen == 16)
+              {
+                char buf[100];
+                if (inet_ntop (AF_INET6, rdata.data, buf, sizeof (buf)) == NULL)
+                  fprintf (mem.out, "error: AAAA record decoding failed: %m\n");
+                else
+                  fprintf (mem.out, "address: %s\n", buf);
+              }
             else
-              fprintf (mem.out, "address: %s\n", buf);
+              fprintf (mem.out, "error: AAAA record of size %d: %s\n",
+                       rdlen, rname.name);
           }
           break;
         case T_CNAME:
         case T_PTR:
           {
             struct dname name;
-            if (extract_name (full, &in, &name))
+            if (extract_name (full, &rdata, &name))
               fprintf (mem.out, "name: %s\n", name.name);
             else
               fprintf (mem.out, "error: malformed CNAME/PTR record\n");