From 4d12e69abb917d38a5577992161b6ec6585d3d2f Mon Sep 17 00:00:00 2001 From: Brad House Date: Tue, 10 Oct 2023 13:07:06 -0400 Subject: [PATCH] Tool: STAYOPEN flag could make tools not terminate (#569) If a flag is set to keep the connections to the DNS servers open even if there are no queries, the tools would not exit until the remote server closed the connection due to the user of ares_fds() to determine if there are any active queries. Instead, rely on ares_timeout() returning NULL if there are no active queries (technically this returns the value passed to max_tv in ares_timeout(), but in our use case, that is always NULL). Fixes Issue: #452 Fix By: Brad House (@bradh352) --- src/tools/acountry.c | 2 ++ src/tools/adig.c | 2 ++ src/tools/ahost.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/tools/acountry.c b/src/tools/acountry.c index 924fab47..85419be4 100644 --- a/src/tools/acountry.c +++ b/src/tools/acountry.c @@ -229,6 +229,8 @@ static void wait_ares(ares_channel channel) if (nfds == 0) break; tvp = ares_timeout(channel, NULL, &tv); + if (tvp == NULL) + break; nfds = select(nfds, &read_fds, &write_fds, NULL, tvp); if (nfds < 0) continue; diff --git a/src/tools/adig.c b/src/tools/adig.c index 28d55ac3..b867be6a 100644 --- a/src/tools/adig.c +++ b/src/tools/adig.c @@ -375,6 +375,8 @@ int main(int argc, char **argv) if (nfds == 0) break; tvp = ares_timeout(channel, NULL, &tv); + if (tvp == NULL) + break; count = select(nfds, &read_fds, &write_fds, NULL, tvp); if (count < 0 && (status = SOCKERRNO) != EINVAL) { diff --git a/src/tools/ahost.c b/src/tools/ahost.c index f8a39eb4..2924e5d5 100644 --- a/src/tools/ahost.c +++ b/src/tools/ahost.c @@ -167,6 +167,8 @@ int main(int argc, char **argv) if (nfds == 0) break; tvp = ares_timeout(channel, NULL, &tv); + if (tvp == NULL) + break; res = select(nfds, &read_fds, &write_fds, NULL, tvp); if (-1 == res) break;