@@ -2049,7 +2049,8 @@ TEST(ServerRequestParsingTest, TrimWhitespaceFromHeaderValues) {
2049
2049
EXPECT_EQ (header_value, " \v bar \e" );
2050
2050
}
2051
2051
2052
- TEST (ServerRequestParsingTest, ReadHeadersRegexComplexity) {
2052
+ // Sends a raw request and verifies that there isn't a crash or exception.
2053
+ static void test_raw_request (const std::string& req) {
2053
2054
Server svr;
2054
2055
svr.Get (" /hi" , [&](const Request & /* req*/ , Response &res) {
2055
2056
res.set_content (" ok" , " text/plain" );
@@ -2066,17 +2067,58 @@ TEST(ServerRequestParsingTest, ReadHeadersRegexComplexity) {
2066
2067
std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
2067
2068
}
2068
2069
2070
+ ASSERT_TRUE (send_request (client_read_timeout_sec, req));
2071
+ svr.stop ();
2072
+ t.join ();
2073
+ EXPECT_TRUE (listen_thread_ok);
2074
+ }
2075
+
2076
+ TEST (ServerRequestParsingTest, ReadHeadersRegexComplexity) {
2069
2077
// A certain header line causes an exception if the header property is parsed
2070
2078
// naively with a single regex. This occurs with libc++ but not libstdc++.
2071
- const std::string req =
2079
+ test_raw_request (
2072
2080
" GET /hi HTTP/1.1\r\n "
2073
2081
" : "
2074
- " " ;
2082
+ " "
2083
+ );
2084
+ }
2075
2085
2076
- ASSERT_TRUE (send_request (client_read_timeout_sec, req));
2077
- svr.stop ();
2078
- t.join ();
2079
- EXPECT_TRUE (listen_thread_ok);
2086
+ TEST (ServerRequestParsingTest, ReadHeadersRegexComplexity2) {
2087
+ // A certain header line causes an exception if the header property *name* is
2088
+ // parsed with a regular expression starting with "(.+?):" - this is a non-
2089
+ // greedy matcher and requires backtracking when there are a lot of ":"
2090
+ // characters.
2091
+ // This occurs with libc++ but not libstdc++.
2092
+ test_raw_request (
2093
+ " GET /hi HTTP/1.1\r\n "
2094
+ " :-:::::::::::::::::::::::::::-::::::::::::::::::::::::@-&&&&&&&&&&&"
2095
+ " --:::::::-:::::::::::::::::::::::::::::-:::::::::::::::::@-&&&&&&&&"
2096
+ " &&&--:::::::-:::::::::::::::::::::::::::::-:::::::::::::::::@-:::::"
2097
+ " ::-:::::::::::::::::@-&&&&&&&&&&&--:::::::-::::::::::::::::::::::::"
2098
+ " :::::-:::::::::::::::::@-&&&&&&&&&&&--:::::::-:::::::::::::::::::::"
2099
+ " ::::::::-:::::::::::::::::@-&&&&&&&--:::::::-::::::::::::::::::::::"
2100
+ " :::::::-:::::::::::::::::@-&&&&&&&&&&&--:::::::-:::::::::::::::::::"
2101
+ " ::::::::::-:::::::::::::::::@-&&&&&::::::::::::-:::::::::::::::::@-"
2102
+ " &&&&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-::::::::::::::::"
2103
+ " :@-&&&&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-:::::::::::::"
2104
+ " ::::@-&&&&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-::::::@-&&"
2105
+ " &&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-:::::::::::::::::@"
2106
+ " ::::::-:::::::::::::::::::::::::::::-:::::::::::::::::@-&&&&&&&&&&&"
2107
+ " --:::::::-:::::::::::::::::::::::::::::-:::::::::::::::::@-&&&&&&&&"
2108
+ " &&&--:::::::-:::::::::::::::::::::::::::::-:::::::::::::::::@-&&&&&"
2109
+ " &&&&&&--:::::::-:::::::::::::::::::::::::::::-:::::::::::::::::@-&&"
2110
+ " &&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-:::::::::::::::::@"
2111
+ " -&&&&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-:::::::::::::::"
2112
+ " ::@-&&&&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-::::::::::::"
2113
+ " :::::@-&&&&&&&&&&&::-:::::::::::::::::@-&&&&&&&&&&&--:::::::-::::::"
2114
+ " :::::::::::::::::::::::-:::::::::::::::::@-&&&&&&&&&&&--:::::::-:::"
2115
+ " ::::::::::::::::::::::::::-:::::::::::::::::@-&&&&&&&&&&&--:::::::-"
2116
+ " :::::::::::::::::::::::::::::-:::::::::::::::::@-&&&&&&&&&&&---&&:&"
2117
+ " &&.0------------:-:::::::::::::::::::::::::::::-:::::::::::::::::@-"
2118
+ " &&&&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-::::::::::::::::"
2119
+ " :@-&&&&&&&&&&&--:::::::-:::::::::::::::::::::::::::::-:::::::::::::"
2120
+ " ::::@-&&&&&&&&&&&---&&:&&&.0------------O--------\r H PUTHTTP/1.1\r\n "
2121
+ " &&&%%%" );
2080
2122
}
2081
2123
2082
2124
TEST (ServerStopTest, StopServerWithChunkedTransmission) {
0 commit comments