]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nss_dns: Validate RDATA length against packet length [BZ #19830]
authorFlorian Weimer <fweimer@redhat.com>
Wed, 27 Apr 2016 13:11:41 +0000 (15:11 +0200)
committerMike Frysinger <vapier@gentoo.org>
Sat, 12 Nov 2016 05:44:25 +0000 (00:44 -0500)
In _nss_dns_getcanonname_r, a check for the availability of RR metadata
was missing as well.

(cherry picked from commit f749498fa53df9ead81e291cd9378d67483c2452)
(cherry picked from commit f233c608d11434aa4a802ded6acdcac1f092729f)

resolv/nss_dns/dns-canon.c
resolv/nss_dns/dns-host.c

index fd73f19984c45cf14f67fb17891541b12599980e..072104f21cc411c0eac5521368804b221c985108 100644 (file)
@@ -103,6 +103,11 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
 
              ptr += s;
 
+             /* Check that there are enough bytes for the RR
+                metadata.  */
+             if (endptr - ptr < 10)
+               goto unavail;
+
              /* Check whether type and class match.  */
              uint_fast16_t type;
              NS_GET16 (type, ptr);
@@ -137,11 +142,16 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
              if (__ns_get16 (ptr) != ns_c_in)
                goto unavail;
 
-             /* Also skip over the TTL.  */
+             /* Also skip over class and TTL.  */
              ptr += sizeof (uint16_t) + sizeof (uint32_t);
 
-             /* Skip over the data length and data.  */
-             ptr += sizeof (uint16_t) + __ns_get16 (ptr);
+             /* Skip over RDATA length and RDATA itself.  */
+             uint16_t rdatalen = __ns_get16 (ptr);
+             ptr += sizeof (uint16_t);
+             /* Not enough room for RDATA.  */
+             if (endptr - ptr < rdatalen)
+               goto unavail;
+             ptr += rdatalen;
            }
        }
 
index 8599f4c6a6ef2781e3fc8450314ede746208fc3d..4bb0e6268a17c7e9cf40656f6b70f9ac8677429f 100644 (file)
@@ -751,6 +751,14 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
       cp += INT32SZ;                   /* TTL */
       n = __ns_get16 (cp);
       cp += INT16SZ;                   /* len */
+
+      if (end_of_message - cp < n)
+       {
+         /* RDATA extends beyond the end of the packet.  */
+         ++had_error;
+         continue;
+       }
+
       if (__glibc_unlikely (class != C_IN))
        {
          /* XXX - debug? syslog? */
@@ -1077,6 +1085,13 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
       n = __ns_get16 (cp);
       cp += INT16SZ;                   /* len */
 
+      if (end_of_message - cp < n)
+       {
+         /* RDATA extends beyond the end of the packet.  */
+         ++had_error;
+         continue;
+       }
+
       if (class != C_IN)
        {
          cp += n;