From 8d06661ade6a5edad0c5111357f9be205ec643ab Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 29 Dec 2015 10:53:45 +0100 Subject: [PATCH] dnsdist: Fix coverity/clang static analyzer warnings. Fix building the unit tests with sanitizers enabled. Coverity complained about d_fp in LogAction not being initialized when constructed from a string, and about negative values from socket() not being handled. Clang static analyzer complained about the count var in addDynBlocks not being initialized in some cases. --- pdns/dnsdist-lua.cc | 4 ++-- pdns/dnsdist-lua2.cc | 2 +- pdns/dnsdistdist/Makefile.am | 3 ++- pdns/dnsrulactions.hh | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index b88f7445cf..6ff72d8abc 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -760,7 +760,7 @@ vector> setupLua(bool client, const std::string& confi return; ComboAddress local(address); try { - int sock = socket(local.sin4.sin_family, SOCK_STREAM, 0); + int sock = SSocket(local.sin4.sin_family, SOCK_STREAM, 0); SSetsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 1); SBind(sock, local); SListen(sock, 5); @@ -788,7 +788,7 @@ vector> setupLua(bool client, const std::string& confi } try { - int sock = socket(local.sin4.sin_family, SOCK_STREAM, 0); + int sock = SSocket(local.sin4.sin_family, SOCK_STREAM, 0); SSetsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 1); SBind(sock, local); SListen(sock, 5); diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 396a11d259..d1838ec19d 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -166,7 +166,7 @@ void moreLua() int actualSeconds = seconds ? *seconds : 10; until.tv_sec += actualSeconds; for(const auto& capair : m) { - unsigned int count; + unsigned int count = 0; if(auto got = slow.lookup(Netmask(capair.first))) { if(until < got->second.until) // had a longer policy continue; diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index 2e451670d2..26ff05ee6f 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -118,5 +118,6 @@ testrunner_LDFLAGS = \ testrunner_LDADD = \ $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) \ $(LIBSODIUM_LIBS) \ - $(RT_LIBS) + $(RT_LIBS) \ + $(SANITIZER_FLAGS) diff --git a/pdns/dnsrulactions.hh b/pdns/dnsrulactions.hh index 21fe32ea43..7da2cddda3 100644 --- a/pdns/dnsrulactions.hh +++ b/pdns/dnsrulactions.hh @@ -443,7 +443,7 @@ public: } private: string d_fname; - FILE* d_fp; + FILE* d_fp{0}; }; -- 2.47.2