From 08000572966dfb74e59a791e06a5522f3be5f064 Mon Sep 17 00:00:00 2001 From: H-Chris233 Date: Mon, 25 May 2026 09:17:41 +0800 Subject: [PATCH 1/2] fix: guard WinHttp URL port parsing exceptions --- src/Utils/WinHttp.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Utils/WinHttp.cpp b/src/Utils/WinHttp.cpp index 21cce65..eb7d4f1 100644 --- a/src/Utils/WinHttp.cpp +++ b/src/Utils/WinHttp.cpp @@ -31,7 +31,13 @@ namespace WinHttp { size_t colon = hostPart.find(':'); if (colon != std::string::npos) { out.host = std::wstring(hostPart.begin(), hostPart.begin() + colon); - out.port = static_cast(std::stoi(hostPart.substr(colon + 1))); + try { + long port = std::stol(hostPart.substr(colon + 1)); + if (port <= 0 || port > 65535) return out; + out.port = static_cast(port); + } catch (...) { + return out; + } } else { out.host = std::wstring(hostPart.begin(), hostPart.end()); } From 37823b93ae698a2c233b75390607d42ae0d5d760 Mon Sep 17 00:00:00 2001 From: H-Chris233 Date: Wed, 27 May 2026 07:54:02 +0800 Subject: [PATCH 2/2] fix: reject partial-numeric port strings in ParseUrl std::stol accepts strings like "12312abc" by parsing only the numeric prefix. Use the pos parameter to verify the entire port substring was consumed, and treat trailing garbage as invalid. --- src/Utils/WinHttp.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Utils/WinHttp.cpp b/src/Utils/WinHttp.cpp index eb7d4f1..9b474cb 100644 --- a/src/Utils/WinHttp.cpp +++ b/src/Utils/WinHttp.cpp @@ -31,9 +31,11 @@ namespace WinHttp { size_t colon = hostPart.find(':'); if (colon != std::string::npos) { out.host = std::wstring(hostPart.begin(), hostPart.begin() + colon); + auto portStr = hostPart.substr(colon + 1); try { - long port = std::stol(hostPart.substr(colon + 1)); - if (port <= 0 || port > 65535) return out; + size_t end = 0; + long port = std::stol(portStr, &end); + if (end != portStr.size() || port <= 0 || port > 65535) return out; out.port = static_cast(port); } catch (...) { return out;