From: ihsinme <61293369+ihsinme@users.noreply.github.com> Date: Fri, 10 Jul 2020 13:12:14 +0000 (+0300) Subject: Update proxy-protocol.cc X-Git-Tag: rec-4.4.0-alpha2^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d73f89a56bb17dd2d8a3834e30da7e8e77716a63;p=thirdparty%2Fpdns.git Update proxy-protocol.cc get rid of integer overflow --- diff --git a/pdns/proxy-protocol.cc b/pdns/proxy-protocol.cc index be635c4241..6cfa5d83e2 100644 --- a/pdns/proxy-protocol.cc +++ b/pdns/proxy-protocol.cc @@ -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::max()) { + valuesSize += sizeof(uint8_t) + sizeof(uint8_t) * 2 + value.content.size(); + if (valuesSize > std::numeric_limits::max()) { throw std::runtime_error("The size of proxy protocol values is limited to " + std::to_string(std::numeric_limits::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;