Skip to content

Commit e3053be

Browse files
committed
Fix port reuse problem
1 parent 2ba0e7a commit e3053be

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

test/test.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10683,10 +10683,12 @@ TEST(VulnerabilityTest, CRLFInjectionInHeaders) {
1068310683
#endif
1068410684
sizeof(on));
1068510685

10686+
httplib::default_socket_options(srv);
10687+
1068610688
sockaddr_in addr{};
1068710689
addr.sin_family = AF_INET;
1068810690
addr.sin_port = htons(PORT);
10689-
::inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
10691+
::inet_pton(AF_INET, HOST, &addr.sin_addr);
1069010692
::bind(srv, reinterpret_cast<sockaddr *>(&addr), sizeof(addr));
1069110693
::listen(srv, 1);
1069210694

@@ -10737,16 +10739,15 @@ TEST(VulnerabilityTest, CRLFInjectionInHeaders) {
1073710739

1073810740
std::this_thread::sleep_for(std::chrono::milliseconds(200));
1073910741

10740-
auto cli = httplib::Client("127.0.0.1", PORT);
10742+
auto cli = httplib::Client(HOST, PORT);
1074110743

1074210744
auto headers = httplib::Headers{
1074310745
{"A", "B\r\n\r\nGET /pwned HTTP/1.1\r\nHost: 127.0.0.1:1234\r\n\r\n"},
1074410746
{"Connection", "keep-alive"}};
1074510747

1074610748
auto res = cli.Get("/hi", headers);
1074710749
EXPECT_FALSE(res);
10748-
10749-
if (res) { EXPECT_EQ(httplib::Error::InvalidHeaders, res.error()); }
10750+
EXPECT_EQ(httplib::Error::InvalidHeaders, res.error());
1075010751

1075110752
server_thread.join();
1075210753
}

0 commit comments

Comments
 (0)