From: Remi Gacogne Date: Mon, 24 Jun 2019 12:31:01 +0000 (+0200) Subject: dnsdist: Add checks for invalid position / buffer size on try* X-Git-Tag: dnsdist-1.4.0-rc1~88^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=000f916edd10b69a42fbe5f1a310ed85e7241e6a;p=pdns dnsdist: Add checks for invalid position / buffer size on try* --- diff --git a/pdns/tcpiohandler.hh b/pdns/tcpiohandler.hh index 33fc402a7..bc4a85f41 100644 --- a/pdns/tcpiohandler.hh +++ b/pdns/tcpiohandler.hh @@ -200,8 +200,8 @@ public: */ IOState tryRead(std::vector& buffer, size_t& pos, size_t toRead) { - if (buffer.size() < (pos + toRead)) { - throw std::out_of_range("Calling tryRead() with a too small buffer (" + std::to_string(buffer.size()) + ") for a read of " + std::to_string(toRead) + " bytes starting at " + std::to_string(pos)); + if (buffer.size() < toRead || pos >= toRead) { + throw std::out_of_range("Calling tryRead() with a too small buffer (" + std::to_string(buffer.size()) + ") for a read of " + std::to_string(toRead - pos) + " bytes starting at " + std::to_string(pos)); } if (d_conn) { @@ -237,6 +237,9 @@ public: */ IOState tryWrite(std::vector& buffer, size_t& pos, size_t toWrite) { + if (buffer.size() < toWrite || pos >= toWrite) { + throw std::out_of_range("Calling tryWrite() with a too small buffer (" + std::to_string(buffer.size()) + ") for a write of " + std::to_string(toWrite - pos) + " bytes starting at " + std::to_string(pos)); + } if (d_conn) { return d_conn->tryWrite(buffer, pos, toWrite); }