]> granicus.if.org Git - pdns/commitdiff
Various fixes from clang static analyzer, coverity and cppcheck
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 4 Apr 2016 12:35:07 +0000 (14:35 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 4 Apr 2016 12:35:07 +0000 (14:35 +0200)
Most of them are simply about making sure that members are
properly initialized by all constructors, especially if there is a
default one. The initialization cost should be fairly small, and I
expect that turning a random failure into a deterministic one is
worth it.

19 files changed:
modules/godbcbackend/sodbc.cc
modules/luabackend/luabackend.hh
modules/pipebackend/pipebackend.cc
pdns/calidns.cc
pdns/dnsbackend.cc
pdns/dnsrecords.hh
pdns/dynloader.cc
pdns/logger.cc
pdns/lwres.hh
pdns/mtasker.hh
pdns/packethandler.hh
pdns/pdns_recursor.cc
pdns/rec_channel.cc
pdns/recursordist/Makefile.am
pdns/rfc2136handler.cc
pdns/toysdig.cc
pdns/webserver.cc
pdns/webserver.hh
pdns/ws-recursor.cc

index b876f32bed38f97eab562a8b828dfcf2999d5116..5c24d6581fe61e80736fb4fa94202d5b0e87b49d 100644 (file)
@@ -53,6 +53,8 @@ public:
     d_dolog = dolog;
     d_residx = 0;
     d_paridx = 0;
+    d_result = SQL_NO_DATA;
+    m_columncount = 0;
 
     // Allocate statement handle.
     result = SQLAllocHandle( SQL_HANDLE_STMT, d_conn, &d_statement );
@@ -232,7 +234,6 @@ public:
 private:
   string d_query;
   bool d_dolog;
-  bool d_havenextrow;
   int d_residx;
   size_t d_paridx,d_parnum;
   SQLRETURN d_result;
index a251ba016a0be7d81e105da12231af4f6a937366..ddab1b4600cb0fda399e21a0497912fc2cfe2258 100644 (file)
@@ -97,7 +97,7 @@ public:
 private:
 
     pthread_t backend_pid;
-    unsigned int backend_count;
+    unsigned int backend_count{0};
 
     int f_lua_exec_error;
 
index 41e19df4cbb702a81f20a6a512279002cdd92da1..7806093d423203c2faf98db39b94f5f41fab1d23 100644 (file)
@@ -96,6 +96,7 @@ void CoWrapper::receive(string &line)
 PipeBackend::PipeBackend(const string &suffix)
 {
    d_disavow=false;
+   d_regex=nullptr;
    signal(SIGCHLD, SIG_IGN);
    setArgPrefix("pipe"+suffix);
    try {
index 979e9b14d8afde889198ccd23c962bca5c849dc9..2696e44a120326b7d8bbc2abe59d364586ea1d4a 100644 (file)
@@ -191,7 +191,7 @@ try
     sockets.push_back(sock);
   }
   new thread(recvThread, &sockets);
-  int qps=atoi(argv[3]);
+  int qps;
 
   ofstream plot("plot");
   for(qps=qpsstart;;qps *= 1.1) {
index e87e0310720d90531fc5c69b31c34f052e2d5c43..76d41872d24e016871db63c0874f45c56e647f36 100644 (file)
@@ -136,7 +136,7 @@ void BackendMakerClass::load_all()
 
 void BackendMakerClass::load(const string &module)
 {
-  int res;
+  bool res;
 
   if(module.find(".")==string::npos)
     res=UeberBackend::loadmodule(arg()["module-dir"]+"/lib"+module+"backend.so");
index 45ea1c425d2f4c1a166a575a9ed4f64fbd480b0d..2b0653dbbe3880a5ff19767d4c6144891801c7f8 100644 (file)
@@ -144,15 +144,15 @@ public:
   includeboilerplate(TSIG)
   TSIGRecordContent() {}
 
-  uint16_t d_origID;
-  uint16_t d_fudge;
+  uint16_t d_origID{0};
+  uint16_t d_fudge{0};
 
   DNSName d_algoName;
   string d_mac;
   string d_otherData;
-  uint64_t d_time;
+  uint64_t d_time{0};
   //  uint16_t d_macSize;
-  uint16_t d_eRcode;
+  uint16_t d_eRcode{0};
   // uint16_t d_otherLen
 };
 
@@ -281,9 +281,9 @@ public:
   uint16_t getTag() const;
   uint16_t getTag();
 
-  uint16_t d_flags;
-  uint8_t d_protocol;
-  uint8_t d_algorithm;
+  uint16_t d_flags{0};
+  uint8_t d_protocol{0};
+  uint8_t d_algorithm{0};
   string d_key;
   bool operator<(const DNSKEYRecordContent& rhs) const
   {
@@ -299,9 +299,9 @@ public:
   includeboilerplate(CDNSKEY)
   uint16_t getTag();
 
-  uint16_t d_flags;
-  uint8_t d_protocol;
-  uint8_t d_algorithm;
+  uint16_t d_flags{0};
+  uint8_t d_protocol{0};
+  uint8_t d_algorithm{0};
   string d_key;
 };
 
@@ -322,8 +322,8 @@ public:
 
   includeboilerplate(DS)
 
-  uint16_t d_tag;
-  uint8_t d_algorithm, d_digesttype;
+  uint16_t d_tag{0};
+  uint8_t d_algorithm{0}, d_digesttype{0};
   string d_digest;
 };
 
@@ -333,8 +333,8 @@ public:
   CDSRecordContent();
   includeboilerplate(CDS)
 
-  uint16_t d_tag;
-  uint8_t d_algorithm, d_digesttype;
+  uint16_t d_tag{0};
+  uint8_t d_algorithm{0}, d_digesttype{0};
   string d_digest;
 };
 
@@ -344,8 +344,8 @@ public:
   DLVRecordContent();
   includeboilerplate(DLV)
 
-  uint16_t d_tag;
-  uint8_t d_algorithm, d_digesttype;
+  uint16_t d_tag{0};
+  uint8_t d_algorithm{0}, d_digesttype{0};
   string d_digest;
 };
 
@@ -419,12 +419,12 @@ public:
   RRSIGRecordContent(); 
   includeboilerplate(RRSIG)
 
-  uint16_t d_type;
-  uint16_t d_tag;
+  uint16_t d_type{0};
+  uint16_t d_tag{0};
   DNSName d_signer;
   string d_signature;
-  uint32_t d_originalttl, d_sigexpire, d_siginception;
-  uint8_t d_algorithm, d_labels;
+  uint32_t d_originalttl{0}, d_sigexpire{0}, d_siginception{0};
+  uint8_t d_algorithm{0}, d_labels{0};
 };
 
 //namespace {
@@ -443,8 +443,8 @@ class RKEYRecordContent : public DNSRecordContent
 public:
   RKEYRecordContent();
   includeboilerplate(RKEY)
-  uint16_t d_flags;
-  uint8_t d_protocol, d_algorithm;
+  uint16_t d_flags{0};
+  uint8_t d_protocol{0}, d_algorithm{0};
   string d_key;
 };
 
@@ -493,8 +493,8 @@ public:
   string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
 
-  uint8_t d_algorithm, d_flags;
-  uint16_t d_iterations;
+  uint8_t d_algorithm{0}, d_flags{0};
+  uint16_t d_iterations{0};
   string d_salt;
   string d_nexthash;
   std::set<uint16_t> d_set;
@@ -528,8 +528,8 @@ public:
   }
 
 
-  uint8_t d_algorithm, d_flags;
-  uint16_t d_iterations;
+  uint8_t d_algorithm{0}, d_flags{0};
+  uint16_t d_iterations{0};
   string d_salt;
 };
 
@@ -547,8 +547,8 @@ public:
   string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
 
-  uint8_t d_version, d_size, d_horizpre, d_vertpre;
-  uint32_t d_latitude, d_longitude, d_altitude;
+  uint8_t d_version{0}, d_size{0}, d_horizpre{0}, d_vertpre{0};
+  uint32_t d_latitude{0}, d_longitude{0}, d_altitude{0};
   uint16_t getType() const override
   {
     return QType::LOC;
@@ -571,7 +571,7 @@ public:
   string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
 
-  uint32_t d_ip;
+  uint32_t d_ip{0};
   std::bitset<65535> d_services;
 private:
 };
@@ -613,17 +613,17 @@ public:
   includeboilerplate(TKEY)
 
   // storage for the bytes
-  uint16_t d_othersize;
-  uint16_t d_mode;
-  uint32_t d_inception;
-  uint32_t d_expiration;
+  uint16_t d_othersize{0};
+  uint16_t d_mode{0};
+  uint32_t d_inception{0};
+  uint32_t d_expiration{0};
 
   DNSName d_algo;
   string d_key;
   string d_other;
 
-  uint16_t d_error;
-  uint16_t d_keysize;
+  uint16_t d_error{0};
+  uint16_t d_keysize{0};
 private:
 };
 
index f1785cbce7231d1eab9e020c9bbb59d2adc104df..4e216412a1979c66940b472c66c824a4c1078b7c 100644 (file)
@@ -176,6 +176,10 @@ int main(int argc, char **argv)
     cerr<<"Fatal error: "<<ae.reason<<endl;
     return 1;
   }
+  catch(const std::runtime_error& e) {
+    cerr<<"Runtime error: "<<e.what()<<endl;
+    return 2;
+  }
   return 0;
 }
 
index a21000466847399b30752a0149287ba77bf0ada8..35e3efd1132e4ba8600828a36f247e5280e775f3 100644 (file)
@@ -101,6 +101,7 @@ Logger::Logger(const string &n, int facility)
   flags=LOG_PID|LOG_NDELAY;
   d_facility=facility;
   d_loglevel=Logger::None;
+  d_disableSyslog=false;
   consoleUrgency=Error;
   name=n;
 
index 9afe0f203221d72efd7bd4bd8f4cdef58fd1e4fd..01338f5d081d8f13c11772ad3d1f22c14087090c 100644 (file)
@@ -60,10 +60,10 @@ public:
   LWResult() : d_usec(0) {}
 
   vector<DNSRecord> d_records;
-  int d_rcode;
-  bool d_aabit, d_tcbit;
-  uint32_t d_usec;
-  bool d_haveEDNS;
+  int d_rcode{0};
+  bool d_aabit{false}, d_tcbit{false};
+  uint32_t d_usec{0};
+  bool d_haveEDNS{false};
 };
 
 int asyncresolve(const ComboAddress& ip, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional<Netmask>& srcmask, LWResult* res);
index 6261e0afaa6a1bc04ee037967cd0335d719b45f0..6e0416fe01b05ae75a2d2eb917da52d5b2c41426 100644 (file)
@@ -99,9 +99,8 @@ public:
       This limit applies solely to the stack, the heap is not limited in any way. If threads need to allocate a lot of data,
       the use of new/delete is suggested. 
    */
-  MTasker(size_t stacksize=8192) : d_stacksize(stacksize)
+  MTasker(size_t stacksize=8192) : d_tid(0), d_maxtid(0), d_stacksize(stacksize), d_waitstatus(Error)
   {
-    d_maxtid=0;
   }
 
   typedef void tfunc_t(void *); //!< type of the pointer that starts a thread 
index 8a88838dcf5a482deef658df68fded136246cb5e..519b789d1b9d363dd5460798b6851bb9b0f7d064 100644 (file)
@@ -108,7 +108,6 @@ private:
   bool d_logDNSDetails;
   bool d_doIPv6AdditionalProcessing;
   bool d_doDNAME;
-  int d_sendRootReferral;
   AuthLua* d_pdl;
 
   UeberBackend B; // every thread an own instance
index 704074ec4af132bb178e05c97ffa7a695a18b14d..20893cb1bd0190a24b50ea926c389e47c4f0702d 100644 (file)
@@ -1150,7 +1150,9 @@ void makeControlChannelSocket(int processNum=-1)
   // do mode change if socket-mode is given
   if(!::arg().isEmpty("socket-mode")) {
     mode_t sockmode=::arg().asMode("socket-mode");
-    chmod(sockname.c_str(), sockmode);
+    if(chmod(sockname.c_str(), sockmode) < 0) {
+      unixDie("Failed to chmod control socket");
+    }
   }
 }
 
index 7cb37a6698c62fb159090d45ec38f28186ce80b3..3c0fb6d87166401024501f26f3d9823b89727b7e 100644 (file)
@@ -21,6 +21,7 @@ RecursorControlChannel::RecursorControlChannel()
 {
   d_fd=-1;
   *d_local.sun_path=0;
+  d_local.sun_family=0;
 }
 
 RecursorControlChannel::~RecursorControlChannel() 
index 0652e808241e0bcfbfbaa1cb49454ea6d7fa5e40..55df2b560e67f3aee12bf175e8757642f307e651 100644 (file)
@@ -1,6 +1,6 @@
 JSON11_LIBS = $(top_srcdir)/ext/json11/libjson11.la
 
-AM_CPPFLAGS = $(LUA_CFLAGS) $(YAHTTP_CFLAGS) $(BOOST_CPPFLAGS) $(SANITIZER_FLAGS) -O3 -Wall -pthread -DSYSCONFDIR=\"${sysconfdir}\"
+AM_CPPFLAGS = $(LUA_CFLAGS) $(YAHTTP_CFLAGS) $(BOOST_CPPFLAGS) $(BOTAN110_CFLAGS) $(SANITIZER_FLAGS) -O3 -Wall -pthread -DSYSCONFDIR=\"${sysconfdir}\"
 
 AM_CPPFLAGS += \
        -I$(top_srcdir)/ext/json11 \
index 1941b564b6a3daf367f52c51740794afc5fa71ac..873bc8149b4b650950e55e891b22fd0debf881cc 100644 (file)
@@ -596,6 +596,10 @@ int PacketHandler::forwardPacket(const string &msgPrefix, DNSPacket *p, DomainIn
     else
       local = ComboAddress("::");
     int sock = makeQuerySocket(local, false); // create TCP socket. RFC2136 section 6.2 seems to be ok with this.
+    if(sock < 0) {
+      L<<Logger::Error<<msgPrefix<<"Error creating socket: "<<stringerror()<<endl;
+      continue;
+    }
 
     if( connect(sock, (struct sockaddr*)&remote, remote.getSocklen()) < 0 ) {
       L<<Logger::Error<<msgPrefix<<"Failed to connect to "<<remote.toStringWithPort()<<": "<<stringerror()<<endl;
index fccbd305b9b5238e44dfe2846b20bf4b00fa988f..42f9002f29614d64d27f67ccc496f8e637cb279a 100644 (file)
@@ -60,8 +60,10 @@ public:
     int numread;
     while(n<len) {
       numread=d_rsock.read(creply+n, len-n);
-      if(numread<0)
+      if(numread<0) {
+        delete[] creply;
         throw PDNSException("tcp read failed: "+std::string(strerror(errno)));
+      }
       n+=numread;
     }
 
index 8635c2c92c1184d606b487aef354376ac4f228af..18bd62086c6647f0d8be0cabb5c84a745d8ba10d 100644 (file)
@@ -209,10 +209,8 @@ static void *WebServerConnectionThreadStart(void *p) {
   return NULL;
 }
 
-HttpResponse WebServer::handleRequest(HttpRequest req)
+void WebServer::handleRequest(HttpRequest& req, HttpResponse& resp)
 {
-  HttpResponse resp;
-
   // set default headers
   resp.headers["Content-Type"] = "text/html; charset=utf-8";
 
@@ -286,8 +284,6 @@ HttpResponse WebServer::handleRequest(HttpRequest req)
   } else {
     resp.headers["Content-Length"] = std::to_string(resp.body.size());
   }
-
-  return resp;
 }
 
 void WebServer::serveConnection(Socket *client)
@@ -316,7 +312,8 @@ try {
     // request stays incomplete
   }
 
-  HttpResponse resp = WebServer::handleRequest(req);
+  HttpResponse resp;
+  WebServer::handleRequest(req, resp);
   ostringstream ss;
   resp.write(ss);
   string reply = ss.str();
index 0e64344d890cc6b414050c345a4585fdf1f8d143..2b60cd02f55392cffe209d7d08370e02e4835003 100644 (file)
@@ -141,7 +141,7 @@ public:
   void go();
 
   void serveConnection(Socket *client);
-  HttpResponse handleRequest(HttpRequest request);
+  void handleRequest(HttpRequest& request, HttpResponse& resp);
 
   typedef boost::function<void(HttpRequest* req, HttpResponse* resp)> HandlerFunction;
   void registerApiHandler(const string& url, HandlerFunction handler);
index 8eb17597f84b730ff97ebb2129fe142195e327ef..72cdf95e824d35e6f2a2650306cad03dfcc577d0 100644 (file)
@@ -584,7 +584,8 @@ void AsyncWebServer::serveConnection(Socket *client)
     // request stays incomplete
   }
 
-  HttpResponse resp = handleRequest(req);
+  HttpResponse resp;
+  handleRequest(req, resp);
   ostringstream ss;
   resp.write(ss);
   data = ss.str();