mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-17 10:59:39 +00:00
Fix UB by use of dangling references in getaddrinfo_with_timeout (#2232)
* Fix use of dangling references When the resolve thread is detached, local variables were still used, which could lead to a program crash. * Add test to verify dangling ref fix * Add missing brace initialization * Assert that the remaining fields are really zeroed * Fix use of chrono literals
This commit is contained in:
1 parent
f72b4582e6
commit
6e52d0a057
2 files changed
+61
-16
No files matched your search
@@ -1331,6 +1331,27 @@ TEST(RangeTest, FromHTTPBin_Online) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GetAddrInfoDanglingRefTest, LongTimeout) {
|
||||
auto host = "unresolvableaddress.local";
|
||||
auto path = std::string{"/"};
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
auto port = 443;
|
||||
SSLClient cli(host, port);
|
||||
#else
|
||||
auto port = 80;
|
||||
Client cli(host, port);
|
||||
#endif
|
||||
cli.set_connection_timeout(1);
|
||||
|
||||
{
|
||||
auto res = cli.Get(path);
|
||||
ASSERT_FALSE(res);
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(8));
|
||||
}
|
||||
|
||||
TEST(ConnectionErrorTest, InvalidHost) {
|
||||
auto host = "-abcde.com";
|
||||
|
||||
|
||||
Reference in new issue
Block a user