From 9e6822773e4277b935e3d03717683c6b806cdd49 Mon Sep 17 00:00:00 2001 From: Richard Hodges Date: Fri, 28 Aug 2020 12:23:40 +0200 Subject: [PATCH] Fix erroneous error when HTTP body_limit is none fixes #2070 closes #2073 --- CHANGELOG.md | 3 ++- include/boost/beast/http/impl/basic_parser.ipp | 6 ++++-- test/beast/http/basic_parser.cpp | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb67b566..6b35b381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -Version XXX: +Version 301: +* Fix erroneous error when HTTP `body_limit` is `none`. * Fix unreachable code warning with MSVC. * Fix logic error in advance_server_flex. * Fix file open with append_existing flag on posix. diff --git a/include/boost/beast/http/impl/basic_parser.ipp b/include/boost/beast/http/impl/basic_parser.ipp index 485a999e..64b402c8 100644 --- a/include/boost/beast/http/impl/basic_parser.ipp +++ b/include/boost/beast/http/impl/basic_parser.ipp @@ -447,7 +447,8 @@ finish_header(error_code& ec, std::true_type) } else if(f_ & flagContentLength) { - if(len_ > body_limit_) + if(body_limit_.has_value() && + len_ > body_limit_) { ec = error::body_limit; return; @@ -511,7 +512,8 @@ finish_header(error_code& ec, std::false_type) f_ |= flagHasBody; state_ = state::body0; - if(len_ > body_limit_) + if(body_limit_.has_value() && + len_ > body_limit_) { ec = error::body_limit; return; diff --git a/test/beast/http/basic_parser.cpp b/test/beast/http/basic_parser.cpp index 5f221f9f..1f2624c1 100644 --- a/test/beast/http/basic_parser.cpp +++ b/test/beast/http/basic_parser.cpp @@ -1500,6 +1500,23 @@ public: } } + void + testUnlimitedBody() + { + const char data[] = + "POST / HTTP/1.1\r\n" + "Content-Length: 5\r\n" + "\r\n" + "*****"; + + test::fail_count fc(1000); + test_parser p(fc); + p.body_limit(none); + error_code ec; + p.put(net::buffer(data, strlen(data)), ec); + BEAST_EXPECTS(!ec, ec.message()); + } + //-------------------------------------------------------------------------- void @@ -1528,6 +1545,7 @@ public: testIssue1267(); testChunkedOverflow(); testChunkedBodySize(); + testUnlimitedBody(); } };