]> git.kaiwu.me - nginx.git/commitdiff
Resolver: fixed off-by-one read in ngx_resolver_copy().
authorMaxim Dounin <mdounin@mdounin.ru>
Tue, 25 May 2021 12:17:38 +0000 (15:17 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Tue, 25 May 2021 12:17:38 +0000 (15:17 +0300)
It is believed to be harmless, and in the worst case it uses some
uninitialized memory as a part of the compression pointer length,
eventually leading to the "name is out of DNS response" error.

src/core/ngx_resolver.c

index 63b26193df4fa0a8ebba9a213e6ca69bbc322b1a..9b131723475e6dc4ef16e2dbcb25ded51f5294a4 100644 (file)
@@ -3958,6 +3958,11 @@ ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src,
         }
 
         if (n & 0xc0) {
+            if (p >= last) {
+                err = "name is out of DNS response";
+                goto invalid;
+            }
+
             n = ((n & 0x3f) << 8) + *p;
             p = &buf[n];