Skip to content

Commit 48084d5

Browse files
committed
Fix #2096
1 parent 5a1ecc3 commit 48084d5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

httplib.h

+3
Original file line numberDiff line numberDiff line change
@@ -4170,6 +4170,9 @@ inline bool parse_header(const char *beg, const char *end, T fn) {
41704170
p++;
41714171
}
41724172

4173+
auto name = std::string(beg, p);
4174+
if (!detail::fields::is_field_name(name)) { return false; }
4175+
41734176
if (p == end) { return false; }
41744177

41754178
auto key_end = p;

test/test.cc

+8
Original file line numberDiff line numberDiff line change
@@ -5156,6 +5156,14 @@ TEST(ServerRequestParsingTest, InvalidFieldValueContains_LF) {
51565156
EXPECT_EQ("HTTP/1.1 400 Bad Request", out.substr(0, 24));
51575157
}
51585158

5159+
TEST(ServerRequestParsingTest, InvalidFieldNameContains_PreceedingSpaces) {
5160+
std::string out;
5161+
std::string request(
5162+
"GET /header_field_value_check HTTP/1.1\r\n Test: val\r\n\r\n", 55);
5163+
test_raw_request(request, &out);
5164+
EXPECT_EQ("HTTP/1.1 400 Bad Request", out.substr(0, 24));
5165+
}
5166+
51595167
TEST(ServerRequestParsingTest, EmptyFieldValue) {
51605168
std::string out;
51615169

0 commit comments

Comments
 (0)