From 4d66b5479ed159b9ccdaf5c49e8f58bd1a15d1df Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Sat, 17 Aug 2024 13:05:51 +0000 Subject: [PATCH] parser uses basic_fields::insert() with error_code overload --- include/boost/beast/http/parser.hpp | 4 ++-- test/beast/http/parser.cpp | 36 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/boost/beast/http/parser.hpp b/include/boost/beast/http/parser.hpp index 4851fe8f31..a5b93d17d4 100644 --- a/include/boost/beast/http/parser.hpp +++ b/include/boost/beast/http/parser.hpp @@ -430,9 +430,9 @@ class parser field name, string_view name_string, string_view value, - error_code&) override + error_code& ec) override { - m_.insert(name, name_string, value); + m_.insert(name, name_string, value, ec); } void diff --git a/test/beast/http/parser.cpp b/test/beast/http/parser.cpp index e6829e2d2f..e1e3cd57b0 100644 --- a/test/beast/http/parser.cpp +++ b/test/beast/http/parser.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace boost { namespace beast { @@ -326,6 +327,40 @@ class parser_test BEAST_EXPECT(used == 0); } + void + testHeaderFieldLimits() + { + auto big_field_name = std::string(fields::max_name_size + 1, 'a'); + auto big_field_value = std::string(fields::max_value_size + 1, 'a'); + + { + parser_type p; + p.header_limit((std::numeric_limits::max)()); + error_code ec; + flat_buffer b; + ostream(b) << + "HTTP/1.1 200 OK\r\n" + << big_field_name + <<": value\r\n" + "\r\n"; + put(b.data(), p, ec); + BEAST_EXPECT(ec == error::header_field_name_too_large); + } + { + parser_type p; + p.header_limit((std::numeric_limits::max)()); + error_code ec; + flat_buffer b; + ostream(b) << + "HTTP/1.1 200 OK\r\n" + << "field: " + << big_field_value << "\r\n" + << "\r\n"; + put(b.data(), p, ec); + BEAST_EXPECT(ec == error::header_field_value_too_large); + } + } + void testIssue818() { @@ -457,6 +492,7 @@ class parser_test testParse(); testNeedMore(); testNeedMore(); + testHeaderFieldLimits(); testGotSome(); testIssue818(); testIssue1187();