From 6a62c0e3b08300f61614ddeee482c806e328466c Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 8 Jan 2016 09:51:38 +0100 Subject: [PATCH] dnsdist: Minor fixes reported by coverity - Handle connection error in client mode - Prevent FPE in some top* functions when no queries were processed - Close Downstream FD in the destructor (no that we really care) --- pdns/dnsdist-console.cc | 5 +++++ pdns/dnsdist-lua.cc | 6 +++--- pdns/dnsdist.hh | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 81f8fdc8a..70b1276a0 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -19,6 +19,10 @@ void doClient(ComboAddress server, const std::string& command) { cout<<"Connecting to "<>> getGenResponses(u else ret.insert({count++, {rc.second.toString(), rc.first, 100.0*rc.first/total}}); } - ret.insert({count, {"Rest", rest, 100.0*rest/total}}); + ret.insert({count, {"Rest", rest, total > 0 ? 100.0*rest/total : 100.0}}); return ret; } @@ -966,7 +966,7 @@ vector> setupLua(bool client, const std::string& confi else g_outputBuffer += (fmt % (count++) % rc.second.toString() % rc.first % (100.0*rc.first/total)).str(); } - g_outputBuffer += (fmt % (count) % "Rest" % rest % (100.0*rest/total)).str(); + g_outputBuffer += (fmt % (count) % "Rest" % rest % (total > 0 ? 100.0*rest/total : 100.0)).str(); }); g_lua.writeFunction("getTopQueries", [](unsigned int top, boost::optional labels) { @@ -1008,7 +1008,7 @@ vector> setupLua(bool client, const std::string& confi else ret.insert({count++, {rc.second.toString(), rc.first, 100.0*rc.first/total}}); } - ret.insert({count, {"Rest", rest, 100.0*rest/total}}); + ret.insert({count, {"Rest", rest, total > 0 ? 100.0*rest/total : 100.0}}); return ret; }); diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 59dd339c9..ed4d873b5 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -280,6 +280,11 @@ struct DownstreamState { DownstreamState(const ComboAddress& remote_, const ComboAddress& sourceAddr_, unsigned int sourceItf); DownstreamState(const ComboAddress& remote_): DownstreamState(remote_, ComboAddress(), 0) {} + ~DownstreamState() + { + if (fd >= 0) + close(fd); + } int fd; std::thread tid; -- 2.40.0