From e6994efe08b282dd9e46602bcbad69567fe91dcd Mon Sep 17 00:00:00 2001 From: tdb3 <106488469+tdb3@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:13:55 -0400 Subject: [PATCH] fix: increase rpcbind check robustness Adds invalid rpcbind port checking to `HTTPBindAddresses()`. While movement of `CheckHostPortOptions()` in the previous commit handles rcpbind port errors, updating `HTTPBindAddresses()` port checking adds a defensive measure for potential future changes. --- src/httpserver.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/httpserver.cpp b/src/httpserver.cpp index ebdab1043e8..ffc53fbd9c8 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,8 @@ #include +using common::InvalidPortErrMsg; + /** Maximum size of http request (request line + headers) */ static const size_t MAX_HEADERS_SIZE = 8192; @@ -374,7 +377,10 @@ static bool HTTPBindAddresses(struct evhttp* http) for (const std::string& strRPCBind : gArgs.GetArgs("-rpcbind")) { uint16_t port{http_port}; std::string host; - SplitHostPort(strRPCBind, port, host); + if (!SplitHostPort(strRPCBind, port, host)) { + LogError("%s\n", InvalidPortErrMsg("-rpcbind", strRPCBind).original); + return false; + } endpoints.emplace_back(host, port); } }