]> git.kaiwu.me - nginx.git/commitdiff
Resolver: limited name length in DNS responses master
authorSergey Kandaurov <pluknet@nginx.com>
Tue, 6 Oct 2026 11:26:23 +0000 (11:26 +0000)
committerSergey Kandaurov <pluknet@nginx.com>
Tue, 24 Nov 2026 16:13:33 +0000 (20:13 +0400)
Names in DNS responses were only limited by the number of labels and
compression pointers, so a name could be expanded to about 8 kilobytes.

Now names longer than 255 octets are rejected, as specified in RFC 1035,
section 3.1.

src/core/ngx_resolver.c

index 9d788eea96cc8b5053f68ae17f0968ca92f77d9a..dc5863360fac9d1831280cdeaff49172e249be01 100644 (file)
@@ -4044,6 +4044,11 @@ ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src,
         n = *p++;
 
         if (n == 0) {
+            if (len > 254) {
+                err = "too long name in DNS response";
+                goto invalid;
+            }
+
             goto done;
         }