From 004062139d57403781d670922490dfa7ca5590e4 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 | 35 +++++++++++++++++++++++++++++ 2 files changed, 37 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..3d26576bc1 100644 --- a/test/beast/http/parser.cpp +++ b/test/beast/http/parser.cpp @@ -326,6 +326,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" + << "name: " + << 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 +491,7 @@ class parser_test testParse(); testNeedMore(); testNeedMore(); + testHeaderFieldLimits(); testGotSome(); testIssue818(); testIssue1187();