]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Update proxy-protocol.cc 9320/head
authorihsinme <61293369+ihsinme@users.noreply.github.com>
Fri, 10 Jul 2020 13:12:14 +0000 (16:12 +0300)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 13:12:14 +0000 (16:12 +0300)
get rid of integer overflow

pdns/proxy-protocol.cc

index be635c4241c34a9dd87655370cac6387ec078050..6cfa5d83e2a2dd220ad3d2bb38932ec72ba83d24 100644 (file)
@@ -65,10 +65,10 @@ std::string makeProxyHeader(bool tcp, const ComboAddress& source, const ComboAdd
 
   size_t valuesSize = 0;
   for (const auto& value : values) {
-    if (value.content.size() > std::numeric_limits<uint16_t>::max()) {
+    valuesSize += sizeof(uint8_t) + sizeof(uint8_t) * 2 + value.content.size();    
+    if (valuesSize > std::numeric_limits<uint16_t>::max()) {
       throw std::runtime_error("The size of proxy protocol values is limited to " + std::to_string(std::numeric_limits<uint16_t>::max()) + ", trying to add a value of size " + std::to_string(value.content.size()));
     }
-    valuesSize += sizeof(uint8_t) + sizeof(uint8_t) * 2 + value.content.size();
   }
 
   size_t total = (addrSize * 2) + sizeof(sourcePort) + sizeof(destinationPort) + valuesSize;