]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use obj.data() instead of &obj.at(0) to prevent exception 6380/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 23 Mar 2018 16:11:43 +0000 (17:11 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 23 Mar 2018 16:11:43 +0000 (17:11 +0100)
In case of a 0-sized container, &obj.at(0) would throw an exception
even if we don't intend to use the pointer afterward.
obj.data is required to provide a non-nullptr pointer that we should
not dereference for most containers (except strings since C++11),
but that's fine for the way we intend (not to) use it.

modules/pipebackend/coprocess.cc
modules/remotebackend/pipeconnector.cc
pdns/dnsdist-tcp.cc
pdns/misc.cc
pdns/opensslsigners.cc
pdns/pkcs11signers.cc
pdns/sodcrypto.cc

index 029a8b8dacef0ae146108cb5bd63ddcf8226c465..f3967301d07c35e06ae9a23f85f63b808fdc2dd0 100644 (file)
@@ -51,7 +51,7 @@ CoProcess::CoProcess(const string &command,int timeout, int infd, int outfd)
   for (size_t n = 0; n < v.size(); n++)
     argv[n]=v[n].c_str();
   // we get away with not copying since nobody resizes v 
-  launch(&argv.at(0), timeout, infd, outfd);
+  launch(argv.data(), timeout, infd, outfd);
 }
 
 void CoProcess::launch(const char **argv, int timeout, int infd, int outfd)
index ba3aaba9a428aa15358bb95f6cfa392354805842..b7fd605ee525793079895461d0e8a8ce7165be41 100644 (file)
@@ -107,7 +107,7 @@ void PipeConnector::launch() {
 
     // stdin & stdout are now connected, fire up our coprocess!
 
-    if(execv(argv[0], const_cast<char * const *>(&argv[0]))<0) // now what
+    if(execv(argv[0], const_cast<char * const *>(argv.data()))<0) // now what
       exit(123);
 
     /* not a lot we can do here. We shouldn't return because that will leave a forked process around.
index 124745f54c989047539b555e9b2282824a30574e..91ee527c408b2ecc6e8c754d2d6370b092569b68 100644 (file)
@@ -561,7 +561,7 @@ void* tcpClientThread(int pipefd)
 #endif
         responseSize += addRoom;
         answerBuffer.resize(responseSize);
-        char* response = &answerBuffer.at(0);
+        char* response = answerBuffer.data();
         readn2WithTimeout(dsock, response, rlen, ds->tcpRecvTimeout);
         uint16_t responseLen = rlen;
         if (outstanding) {
index 11d31f4e85b8a96b67d3e19d493951f283a39f47..78ec742b9b674b2831f66b60270bbc7425e0d8b4 100644 (file)
@@ -363,7 +363,7 @@ int waitForMultiData(const set<int>& fds, const int seconds, const int useconds,
   }
 
   std::vector<struct pollfd> pfds(realFDs.size());
-  memset(&pfds.at(0), 0, realFDs.size()*sizeof(struct pollfd));
+  memset(pfds.data(), 0, realFDs.size()*sizeof(struct pollfd));
   int ctr = 0;
   for (const auto& fd : realFDs) {
     pfds[ctr].fd = fd;
@@ -373,9 +373,9 @@ int waitForMultiData(const set<int>& fds, const int seconds, const int useconds,
 
   int ret;
   if(seconds >= 0)
-    ret = poll(&pfds.at(0), realFDs.size(), seconds * 1000 + useconds/1000);
+    ret = poll(pfds.data(), realFDs.size(), seconds * 1000 + useconds/1000);
   else
-    ret = poll(&pfds.at(0), realFDs.size(), -1);
+    ret = poll(pfds.data(), realFDs.size(), -1);
   if(ret <= 0)
     return ret;
 
index 3176744d45ac22739ae8837d6c32c86369e918a8..daff5a538480a4d1012f1c8ed5924fd5c5fc54ec 100644 (file)
@@ -388,14 +388,14 @@ std::string OpenSSLRSADNSCryptoKeyEngine::getPubKeyHash() const
     throw runtime_error(getName()+" failed to init hash context for generating the public key hash");
   }
 
-  int len = BN_bn2bin(e, &tmp.at(0));
-  res = SHA1_Update(&ctx, &tmp.at(0), len);
+  int len = BN_bn2bin(e, tmp.data());
+  res = SHA1_Update(&ctx, tmp.data(), len);
   if (res != 1) {
     throw runtime_error(getName()+" failed to update hash context for generating the public key hash");
   }
 
-  len = BN_bn2bin(n, &tmp.at(0));
-  res = SHA1_Update(&ctx, &tmp.at(0), len);
+  len = BN_bn2bin(n, tmp.data());
+  res = SHA1_Update(&ctx, tmp.data(), len);
   if (res != 1) {
     throw runtime_error(getName()+" failed to update hash context for generating the public key hash");
   }
index 4ad764c488c41a6ba5df8c29db5e1d4e99b78e10..041cb8c177d976ca5b4e3f11482b07d21f5f25c7 100644 (file)
@@ -673,7 +673,7 @@ CK_RV Pkcs11Slot::HuntSlot(const string& tokenId, CK_SLOT_ID &slotId, _CK_SLOT_I
 
   // get the actual slot ids
   std::vector<CK_SLOT_ID> slotIds(slots);
-  err = functions->C_GetSlotList(CK_FALSE, &slotIds.at(0), &slots);
+  err = functions->C_GetSlotList(CK_FALSE, slotIds.data(), &slots);
   if (err) {
     L<<Logger::Warning<<"C_GetSlotList(CK_FALSE, slotIds, &slots) = " << err << std::endl;
     return err;
index daff010ff6b966e232885f8cc89aa32531cd2d90..2bdf5beaf27846e65242a918610951d8bbaf651e 100644 (file)
@@ -62,7 +62,7 @@ std::string sodDecryptSym(const std::string& msg, const std::string& key, Sodium
 
   decrypted.resize(msg.length() - crypto_secretbox_MACBYTES);
 
-  if (crypto_secretbox_open_easy(reinterpret_cast<unsigned char*>(&decrypted.at(0)),
+  if (crypto_secretbox_open_easy(reinterpret_cast<unsigned char*>(const_cast<char *>(decrypted.data())),
                                  reinterpret_cast<const unsigned char*>(msg.c_str()),
                                  msg.length(),
                                  nonce.value,