From: Remi Gacogne Date: Wed, 8 Mar 2023 17:25:30 +0000 (+0100) Subject: YaHTTP: Prevent integer overflow on very large chunks X-Git-Tag: rec-4.8.5~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F13078%2Fhead;p=thirdparty%2Fpdns.git YaHTTP: Prevent integer overflow on very large chunks If the chunk_size is very close to the maximum value of an integer, we trigger an integer overflow when checking if we have a trailing newline after the payload. Reported by OSS-Fuzz as: https://oss-fuzz.com/testcase-detail/6439610474692608 https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=56804 (cherry picked from commit b602982fc5b4fb9139dec591541e0c070ceb47f5) --- diff --git a/ext/yahttp/yahttp/reqresp.cpp b/ext/yahttp/yahttp/reqresp.cpp index dc49cb64f6..e5f9c95ecc 100644 --- a/ext/yahttp/yahttp/reqresp.cpp +++ b/ext/yahttp/yahttp/reqresp.cpp @@ -1,5 +1,7 @@ #include "yahttp.hpp" +#include + namespace YaHTTP { template class AsyncLoader; @@ -177,6 +179,9 @@ namespace YaHTTP { throw ParseError("Unable to parse chunk size"); } if (chunk_size == 0) { state = 3; break; } // last chunk + if (chunk_size > (std::numeric_limits::max() - 2)) { + throw ParseError("Chunk is too large"); + } } else { int crlf=1; if (buffer.size() < static_cast(chunk_size+1)) return false; // expect newline