]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Only call std::string::reserve() when needed in hashQNameWithSalt()
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 6 Jan 2021 09:25:12 +0000 (10:25 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Jan 2021 11:12:51 +0000 (12:12 +0100)
pdns/dnssecinfra.cc

index 152fd3bf80eec1d85e0c2cd64f3196d8859482f0..110f5f1dfaa71fc2f8f1e05abd3b0893864a702a 100644 (file)
@@ -494,9 +494,6 @@ string hashQNameWithSalt(const std::string& salt, unsigned int iterations, const
   unsigned int times = iterations;
   unsigned char hash[SHA_DIGEST_LENGTH];
   string toHash(qname.toDNSStringLC() + salt);
-  if (toHash.capacity() < (salt.size() + sizeof(hash))) {
-    toHash.reserve(salt.size() + sizeof(hash));
-  }
 
   for (;;) {
     /* so the first time we hash the (lowercased) qname plus the salt,
@@ -511,6 +508,9 @@ string hashQNameWithSalt(const std::string& salt, unsigned int iterations, const
       /* first time, we need to replace the qname + salt with
          the hash plus salt, since the qname will not likely
          match the size of the hash */
+      if (toHash.capacity() < (sizeof(hash) + salt.size())) {
+        toHash.reserve(sizeof(hash) + salt.size());
+      }
       toHash.assign(reinterpret_cast<char*>(hash), sizeof(hash));
       toHash.append(salt);
     }