File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -1847,7 +1847,7 @@ inline bool read_headers(Stream &strm, Headers &headers) {
18471847 // the left or right side of the header value:
18481848 // - https://stackoverflow.com/questions/50179659/
18491849 // - https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
1850- static const std::regex re (R"( ([^:]+):[\t ]*(.+ ))" );
1850+ static const std::regex re (R"( ([^:]+):[\t ]*([^\t ].* ))" );
18511851
18521852 std::cmatch m;
18531853 if (std::regex_match (line_reader.ptr (), end, m, re)) {
Original file line number Diff line number Diff line change @@ -2333,6 +2333,19 @@ TEST(ServerRequestParsingTest, ReadHeadersRegexComplexity2) {
23332333 " &&&%%%" );
23342334}
23352335
2336+ TEST (ServerRequestParsingTest, ExcessiveWhitespaceInUnparseableHeaderLine) {
2337+ // Make sure this doesn't crash the server.
2338+ // In a previous version of the header line regex, the "\r" rendered the line
2339+ // unparseable and the regex engine repeatedly backtracked, trying to look for
2340+ // a new position where the leading white space ended and the field value
2341+ // began.
2342+ // The crash occurs with libc++ but not libstdc++.
2343+ test_raw_request (" GET /hi HTTP/1.1\r\n "
2344+ " a:" + std::string (2000 , ' ' ) + ' \r ' + std::string (20 , ' z' ) +
2345+ " \r\n "
2346+ " \r\n " );
2347+ }
2348+
23362349TEST (ServerRequestParsingTest, InvalidFirstChunkLengthInRequest) {
23372350 std::string out;
23382351
You can’t perform that action at this time.
0 commit comments