[PATCH 4 of 6] Resolver: protection from duplicate PTR responses

Maxim Dounin mdounin at mdounin.ru
Tue Dec 1 03:58:37 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1796094134 -10800
#      Tue Dec 01 06:02:14 2026 +0300
# Node ID 4f0609931e7ee2d3deb23b6a77ca25e3c421d13c
# Parent  eb3276d36c328f0c8fa611ce5e8a5c06fe86a159
Resolver: protection from duplicate PTR responses.

Similarly to duplicate A and CNAME responses (see 4619:3171ec7d0d05),
duplicate PTR responses are now rejected.  In contrast to duplicate A
and CNAME responses, these are mostly harmless, yet there are no reasons
to accept them anyway.

While here, removed unneeded rn->query6 clearing.  The rn->query6 field
is not used for PTR queries, and doesn't need to be cleared.

diff --git a/src/core/ngx_resolver.c b/src/core/ngx_resolver.c
--- a/src/core/ngx_resolver.c
+++ b/src/core/ngx_resolver.c
@@ -982,11 +982,10 @@ ngx_resolve_addr(ngx_resolver_ctx_t *ctx
 
         ngx_queue_remove(&rn->queue);
 
-        ngx_resolver_free(r, rn->query);
-        rn->query = NULL;
-#if (NGX_HAVE_INET6)
-        rn->query6 = NULL;
-#endif
+        if (rn->query) {
+            ngx_resolver_free(r, rn->query);
+            rn->query = NULL;
+        }
 
     } else {
         rn = ngx_resolver_calloc(r, sizeof(ngx_resolver_node_t));
@@ -3268,6 +3267,9 @@ ptr:
 
     ngx_resolver_free(r, name.data);
 
+    ngx_resolver_free(r, rn->query);
+    rn->query = NULL;
+
     return;
 
 short_response:



More information about the nginx-devel mailing list