fix rejection of dns responses with pointers past 512 byte offset review
authorRich Felker <dalias@aerifal.cx>
Mon, 17 Jul 2023 22:03:38 +0000 (18:03 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 17 Jul 2023 22:03:38 +0000 (18:03 -0400)
the __dns_parse code used by the stub resolver traditionally included
code to reject label pointers to offsets past a 512 byte limit,
despite never processing the label contents, only stepping over them.
when commit 51d4669fb97782f6a66606da852b5afd49a08001 added support for
tcp fallback, this limit was overlooked, and as a result, it was at
least theoretically possible for some valid large answers to be
rejected on account of these offsets.

since the limit was never serving any useful purpose, just remove it.

src/network/dns_parse.c

index 7f83e79..ea1ec12 100644 (file)
@@ -15,13 +15,13 @@ int __dns_parse(const unsigned char *r, int rlen, int (*callback)(void *, int, c
        if (qdcount+ancount > 64) return -1;
        while (qdcount--) {
                while (p-r < rlen && *p-1U < 127) p++;
-               if (p>r+rlen-6 || *p>193 || (*p==193 && p[1]>254))
+               if (p>r+rlen-6)
                        return -1;
                p += 5 + !!*p;
        }
        while (ancount--) {
                while (p-r < rlen && *p-1U < 127) p++;
-               if (p>r+rlen-12 || *p>193 || (*p==193 && p[1]>254))
+               if (p>r+rlen-12)
                        return -1;
                p += 1 + !!*p;
                len = p[8]*256 + p[9];