From d5bb60bbc5ff2bbf1dcf162b045b0c2957102a5c Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Sat, 2 Dec 2023 15:58:41 +0100 Subject: [PATCH] HTTP: don't crash for resolve errors --- src/http/http.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/http/http.h b/src/http/http.h index 5c389186..649fda34 100644 --- a/src/http/http.h +++ b/src/http/http.h @@ -139,7 +139,12 @@ class HTTP { if (strcasecmp(proto.c_str(), "https") == 0) { if (port.empty()) port = "443"; resolver = new tcp::resolver(io_context); - auto endpoints = resolver->resolve(host, port); + asio::error_code ec; + auto endpoints = resolver->resolve(host, port, ec); + if (ec) { + std::cout << "HTTP: failed to resolve host: " << ec.message() << "\n"; + return false; + } asio::ssl::context ctx(asio::ssl::context::tlsv12_client); ctx.set_options(asio::ssl::context::default_workarounds @@ -183,7 +188,12 @@ class HTTP { else if (strcasecmp(proto.c_str(), "http") == 0) { if (port.empty()) port = "80"; resolver = new tcp::resolver(io_context); - auto endpoints = resolver->resolve(host, port); + asio::error_code ec; + auto endpoints = resolver->resolve(host, port, ec); + if (ec) { + std::cout << "HTTP: failed to resolve host: " << ec.message() << "\n"; + return false; + } c = new tcp_client(io_context, endpoints, request); } else {