From 31a1fb332a8f69ae35853216de2bcbe96df3f19b Mon Sep 17 00:00:00 2001 From: Michael Haubenschild Date: Thu, 18 Mar 2021 21:05:04 +0100 Subject: [PATCH] Fix missing check for error code after header is parsed: The missing error check leads to completely ignoring the body limit, as the body limit is compared to the "Content-Length" header inside the "finish_header" method. closes #2201 --- CHANGELOG.md | 3 ++- include/boost/beast/http/impl/basic_parser.ipp | 2 ++ test/beast/http/basic_parser.cpp | 18 ++++++++++++++++++ test/beast/http/test_parser.hpp | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 134d85ee..f0b317a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ -* Fix case where inflated content is larger than out buffer. +* Fix missing check for error code after header is parsed. +* Fix case where inflated content is larger than the out buffer. -------------------------------------------------------------------------------- diff --git a/include/boost/beast/http/impl/basic_parser.ipp b/include/boost/beast/http/impl/basic_parser.ipp index 6fac00c3..4eff491c 100644 --- a/include/boost/beast/http/impl/basic_parser.ipp +++ b/include/boost/beast/http/impl/basic_parser.ipp @@ -164,6 +164,8 @@ loop: goto done; } finish_header(ec, is_request{}); + if(ec) + goto done; break; case state::body0: diff --git a/test/beast/http/basic_parser.cpp b/test/beast/http/basic_parser.cpp index 1f2624c1..e89d3c0f 100644 --- a/test/beast/http/basic_parser.cpp +++ b/test/beast/http/basic_parser.cpp @@ -1517,6 +1517,23 @@ public: BEAST_EXPECTS(!ec, ec.message()); } + void + testIssue2201() + { + const char data[] = + "HTTP/1.1 200 OK\r\n" + "Content-Length: 5\r\n" + "\r\n" + "*****"; + + test_parser p; + p.eager(true); + p.body_limit(3); + error_code ec; + p.put(net::buffer(data, strlen(data)), ec); + BEAST_EXPECT(ec == error::body_limit); + } + //-------------------------------------------------------------------------- void @@ -1546,6 +1563,7 @@ public: testChunkedOverflow(); testChunkedBodySize(); testUnlimitedBody(); + testIssue2201(); } }; diff --git a/test/beast/http/test_parser.hpp b/test/beast/http/test_parser.hpp index a12ad2b4..d5d70327 100644 --- a/test/beast/http/test_parser.hpp +++ b/test/beast/http/test_parser.hpp @@ -104,6 +104,8 @@ public: boost::optional const& content_length_, error_code& ec) { + // The real implementation clears out the error code in basic_string_body::reader::init + ec = {}; ++got_on_body; got_content_length = static_cast(content_length_);