aboutsummaryrefslogtreecommitdiff
path: root/resolv/nss_dns/dns-canon.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-04-27 15:11:41 +0200
committerFlorian Weimer <fweimer@redhat.com>2016-04-27 15:11:42 +0200
commitf749498fa53df9ead81e291cd9378d67483c2452 (patch)
tree6d4153c36df6d2a75e43ea51584f3664b5695ac8 /resolv/nss_dns/dns-canon.c
parentb9bdfa7c8fa22c944bb5f21a673dfd1f91b71c56 (diff)
downloadglibc-f749498fa53df9ead81e291cd9378d67483c2452.zip
glibc-f749498fa53df9ead81e291cd9378d67483c2452.tar.gz
glibc-f749498fa53df9ead81e291cd9378d67483c2452.tar.bz2
nss_dns: Validate RDATA length against packet length [BZ #19830]
In _nss_dns_getcanonname_r, a check for the availability of RR metadata was missing as well.
Diffstat (limited to 'resolv/nss_dns/dns-canon.c')
-rw-r--r--resolv/nss_dns/dns-canon.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/resolv/nss_dns/dns-canon.c b/resolv/nss_dns/dns-canon.c
index fd73f19..072104f 100644
--- a/resolv/nss_dns/dns-canon.c
+++ b/resolv/nss_dns/dns-canon.c
@@ -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;
}
}