]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Silence false positives about unintialized values
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Jan 2021 15:59:21 +0000 (16:59 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Jan 2021 15:59:21 +0000 (16:59 +0100)
pdns/dnscrypt.hh
pdns/dnsdist.hh
pdns/doh.hh
pdns/sodcrypto.hh
pdns/test-dnscrypt_cc.cc
pdns/test-dnsdist_cc.cc

index a9a579e9c40d8a428b7cfec22981ef5af08fc089..8139e281e55eef306a3a2f1ea693c695a597a651 100644 (file)
@@ -175,7 +175,12 @@ class DNSCryptQuery
 public:
   DNSCryptQuery(const std::shared_ptr<DNSCryptContext>& ctx): d_ctx(ctx)
   {
+    memset(&d_header, 0, sizeof(d_header));
+#ifdef HAVE_CRYPTO_BOX_EASY_AFTERNM
+    memset(&d_sharedKey, 0, sizeof(d_sharedKey));
+#endif /* HAVE_CRYPTO_BOX_EASY_AFTERNM */
   }
+
   ~DNSCryptQuery();
 
   bool isValid() const
index 7b63403fb93c1453d6ff11a5ec8beb5b87906e13..d93340a3713af16cf9c1a29134c17b108b78586a 100644 (file)
@@ -138,8 +138,8 @@ public:
   struct DOHUnit* du{nullptr};
   int delayMsec{0};
   boost::optional<uint32_t> tempFailureTTL;
-  uint32_t cacheKeyNoECS;
-  uint32_t cacheKey;
+  uint32_t cacheKeyNoECS{0};
+  uint32_t cacheKey{0};
   const uint16_t qtype;
   const uint16_t qclass;
   uint16_t ecsPrefixLength;
@@ -492,7 +492,7 @@ public:
 
 protected:
   mutable StopWatch d_prev;
-  mutable double d_tokens;
+  mutable double d_tokens{0.0};
 };
 
 class QPSLimiter : public BasicQPSLimiter
@@ -538,8 +538,8 @@ public:
   }
 
 private:
-  unsigned int d_rate;
-  unsigned int d_burst;
+  unsigned int d_rate{0};
+  unsigned int d_burst{0};
   bool d_passthrough{true};
 };
 
@@ -681,13 +681,13 @@ struct IDState
   std::shared_ptr<QTag> qTag{nullptr};
   const ClientState* cs{nullptr};
   DOHUnit* du{nullptr};
-  uint32_t cacheKey;                                          // 4
-  uint32_t cacheKeyNoECS;                                     // 4
-  uint16_t age;                                               // 4
-  uint16_t qtype;                                             // 2
-  uint16_t qclass;                                            // 2
-  uint16_t origID;                                            // 2
-  uint16_t origFlags;                                         // 2
+  uint32_t cacheKey{0};                                       // 4
+  uint32_t cacheKeyNoECS{0};                                  // 4
+  uint16_t age{0};                                            // 4
+  uint16_t qtype{0};                                          // 2
+  uint16_t qclass{0};                                         // 2
+  uint16_t origID{0};                                         // 2
+  uint16_t origFlags{0};                                      // 2
   int origFD{-1};
   int delayMsec{0};
   boost::optional<uint32_t> tempFailureTTL;
index eba05c80401d0409754d69e871e757c0e805b23a..990369276651531a5fa21210346b361fa691b545 100644 (file)
@@ -208,7 +208,7 @@ struct DOHUnit
   std::string contentType;
   std::atomic<uint64_t> d_refcnt{1};
   size_t query_at{0};
-  int rsock;
+  int rsock{-1};
   /* the status_code is set from
      processDOHQuery() (which is executed in
      the DOH client thread) so that the correct
index cfcd7eff0dddde5e505b4e82be363720aa6c1f10..ca35631455de7cc3f5afb3724fd4ac5213d36289 100644 (file)
@@ -32,13 +32,18 @@ struct SodiumNonce
   void init(){};
   void merge(const SodiumNonce& lower, const SodiumNonce& higher) {};
   void increment(){};
-  unsigned char value[1];
+  unsigned char value[1]{0};
 };
 #else
 #include <sodium.h>
 
 struct SodiumNonce
 {
+  SodiumNonce()
+  {
+    memset(&value, 0, sizeof(value));
+  }
+
   void init()
   {
     randombytes_buf(value, sizeof value);
index f3627971fa7f4b459dc859e3d93a55b724bc199a..c74dc6153ab1c36ac7c4db869360ef1b7ebe1685 100644 (file)
@@ -143,12 +143,6 @@ BOOST_AUTO_TEST_CASE(DNSCryptEncryptedQueryValid) {
   PacketBuffer plainQuery;
   GenericDNSPacketWriter<PacketBuffer> pw(plainQuery, name, QType::AAAA, QClass::IN, 0);
   pw.getHeader()->rd = 1;
-  size_t requiredSize = plainQuery.size() + sizeof(DNSCryptQueryHeader) + DNSCRYPT_MAC_SIZE;
-  if (requiredSize < DNSCryptQuery::s_minUDPLength) {
-    requiredSize = DNSCryptQuery::s_minUDPLength;
-  }
-
-  plainQuery.resize(requiredSize);
 
   size_t initialSize = plainQuery.size();
   int res = ctx->encryptQuery(plainQuery, 4096, clientPublicKey, clientPrivateKey, clientNonce, false, std::make_shared<DNSCryptCert>(resolverCert));
@@ -225,11 +219,6 @@ BOOST_AUTO_TEST_CASE(DNSCryptEncryptedQueryValidWithOldKey) {
   GenericDNSPacketWriter<PacketBuffer> pw(plainQuery, name, QType::AAAA, QClass::IN, 0);
   pw.getHeader()->rd = 1;
 
-  size_t requiredSize = plainQuery.size() + sizeof(DNSCryptQueryHeader) + DNSCRYPT_MAC_SIZE;
-  if (requiredSize < DNSCryptQuery::s_minUDPLength) {
-    requiredSize = DNSCryptQuery::s_minUDPLength;
-  }
-
   size_t initialSize = plainQuery.size();
   int res = ctx->encryptQuery(plainQuery, 4096, clientPublicKey, clientPrivateKey, clientNonce, false, std::make_shared<DNSCryptCert>(resolverCert));
 
index 638c74a735b899b44ebf0f0531297448c8fc5f1c..d17e9a0c60bca84c8a0e29f344d6f59b47002b11 100644 (file)
@@ -1709,8 +1709,8 @@ BOOST_AUTO_TEST_CASE(test_isEDNSOptionInOpt) {
   */
   const ComboAddress lc("127.0.0.1");
   const ComboAddress rem("127.0.0.1");
-  size_t optContentStart;
-  uint16_t optContentLen;
+  size_t optContentStart{std::numeric_limits<size_t>::max()};
+  uint16_t optContentLen{0};
 
   const size_t optRDExpectedOffset = sizeof(dnsheader) + qname.wirelength() + DNS_TYPE_SIZE + DNS_CLASS_SIZE + /* root */ 1 + DNS_TYPE_SIZE + DNS_CLASS_SIZE + DNS_TTL_SIZE;