From 079c609424bf4291c984bfe8d26ba87405493b28 Mon Sep 17 00:00:00 2001 From: Emeric Brun Date: Thu, 17 Jun 2021 18:23:04 +0200 Subject: [PATCH] BUG/MEDIUM: dns: send messages on closed/reused fd if fd was detected broken This fix complete this incomplete bug fix '(751872e4)': 'BUG/MEDIUM: dns: reset file descriptor if send returns an error This previous patch detects error on fd and close this one but the code continues the loop on pending queries and try to send them using the previously closed fd which could be reused by an other thread. This patch stop to send queries on this fd and count them on snd_error counter. This patch applies on branch 2.3 and all this stuff is already fixed in newer version by '(d26a6237ad)': 'MEDIUM: resolvers: split resolving and dns message exchange layers' This patch should be backported on all branches including the previous fix '(751872e4)': 'BUG/MEDIUM: dns: reset file descriptor if send returns an error' --- src/dns.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dns.c b/src/dns.c index 8421a0b..dbefb8e 100644 --- a/src/dns.c +++ b/src/dns.c @@ -2174,6 +2174,10 @@ static void dns_resolve_send(struct dgram_conn *dgram) if (res->nb_queries == resolvers->nb_nameservers) continue; + /* if fd was detected broken by previous send */ + if (fd == -1) + goto snd_error; + len = dns_build_query(res->query_id, res->query_type, resolvers->accepted_payload_size, res->hostname_dn, res->hostname_dn_len, @@ -2196,7 +2200,7 @@ static void dns_resolve_send(struct dgram_conn *dgram) * nameserver */ fd_delete(fd); - dgram->t.sock.fd = -1; + fd = dgram->t.sock.fd = -1; } goto snd_error; } -- 1.7.10.4