From 14eecc6e2aff61f4fd56ce4458462be02155466e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=D0=B5=D0=BB=D0=BE=D0=B2=20=D0=9C?= =?UTF-8?q?=D0=B0=D0=BA=D1=81=D0=B8=D0=BC?= <53077323+mmarkeloff@users.noreply.github.com> Date: Tue, 7 Sep 2021 09:10:25 +0300 Subject: [PATCH] Unhandled errors inet_aton(), InetPton() return codes --- include/spdlog/details/udp_client-windows.h | 6 +++++- include/spdlog/details/udp_client.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/udp_client-windows.h b/include/spdlog/details/udp_client-windows.h index f45a5600..5cc3dd88 100644 --- a/include/spdlog/details/udp_client-windows.h +++ b/include/spdlog/details/udp_client-windows.h @@ -64,7 +64,11 @@ public: addr_.sin_family = PF_INET; addr_.sin_port = htons(port); addr_.sin_addr.s_addr = INADDR_ANY; - InetPton(PF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr); + if (InetPton(PF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr) != 1) { + int last_error = ::WSAGetLastError(); + ::WSACleanup(); + throw_winsock_error_("error: Invalid address!", last_error); + } socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); if (socket_ == INVALID_SOCKET) diff --git a/include/spdlog/details/udp_client.h b/include/spdlog/details/udp_client.h index 6d0919b6..ccdf2f0b 100644 --- a/include/spdlog/details/udp_client.h +++ b/include/spdlog/details/udp_client.h @@ -58,7 +58,11 @@ public: sockAddr_.sin_family = AF_INET; sockAddr_.sin_port = htons(port); - ::inet_aton(host.c_str(), &sockAddr_.sin_addr); + + if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) { + cleanup_(); + throw_spdlog_ex("error: Invalid address!"); + } ::memset(sockAddr_.sin_zero, 0x00, sizeof(sockAddr_.sin_zero)); }