
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1621945058 -10800
# Node ID 5d561a77502e2b9570906f12e0d085721b558997
# Parent  7f702d35ac38abc358c0df154fd9c9e5df678395
Resolver: fixed off-by-one read in ngx_resolver_copy().

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.

--- a/src/core/ngx_resolver.c
+++ b/src/core/ngx_resolver.c
@@ -3943,6 +3943,11 @@ ngx_resolver_copy(ngx_resolver_t *r, ngx
         }
 
         if (n & 0xc0) {
+            if (p >= last) {
+                err = "name is out of DNS response";
+                goto invalid;
+            }
+
             n = ((n & 0x3f) << 8) + *p;
             p = &buf[n];
 
