BUG/MINOR: resolvers: Fix condition to release received ARs if not assigned
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 23 Feb 2021 10:59:19 +0000 (11:59 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 24 Feb 2021 21:25:08 +0000 (22:25 +0100)
At the end of resolv_validate_dns_response(), if a received additionnal
record is not assigned to an existing server record, it is released. But the
condition to do so is buggy. If "answer_record" (the received AR) is not
assigned, "tmp_record" is not a valid record object. It is just a dummy
record "representing" the head of the record list.

Now, the condition is far cleaner. This patch must be backported as far as
2.2.

(cherry picked from commit 9c246a4b6ce3fa0e70399e0158866d41b8662a7f)
[cf: Changes applied in src/dns.c]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/dns.c

index 7aef957..3fcf434 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -1287,12 +1287,14 @@ static int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend,
                                    !dns_hostname_cmp(tmp_record->target, dns_answer_record->name, tmp_record->data_len)) {
                                        /* Always use the received additional record to refresh info */
                                        tmp_record->ar_item = dns_answer_record;
+                                       dns_answer_record = NULL;
                                        break;
                                }
                        }
-                       if (tmp_record->ar_item != dns_answer_record)
+                       if (dns_answer_record) {
                                pool_free(dns_answer_item_pool, dns_answer_record);
-                       dns_answer_record = NULL;
+                               dns_answer_record = NULL;
+                       }
                }
        } /* for i 0 to arcount */