From d73f89a56bb17dd2d8a3834e30da7e8e77716a63 Mon Sep 17 00:00:00 2001 From: ihsinme <61293369+ihsinme@users.noreply.github.com> Date: Fri, 10 Jul 2020 16:12:14 +0300 Subject: [PATCH] Update proxy-protocol.cc get rid of integer overflow --- pdns/proxy-protocol.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; -- 2.47.2