From: Remi Gacogne Date: Fri, 8 Jan 2016 08:51:38 +0000 (+0100) Subject: dnsdist: Minor fixes reported by coverity X-Git-Tag: dnsdist-1.0.0-alpha2~109^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a62c0e3b08300f61614ddeee482c806e328466c;p=pdns 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) --- 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;