aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-09-02 12:50:12 +0100
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-09-07 12:14:53 +0200
commit38d4601fe826069ee43b341e9d467beb7d14b5f0 (patch)
treebc3309ea3813ae10df8eb709fbcc01098cdf556c /src
parent313ea18e5e72df185935d06491dd823163eefa87 (diff)
downloadbitcoin-38d4601fe826069ee43b341e9d467beb7d14b5f0.tar.xz
Prevent data race for `pathHandlers`
Github-Pull: bitcoin/bitcoin#25983 Rebased-From: 4296dde28757d88a7076847484669fb202b47bc8
Diffstat (limited to 'src')
-rw-r--r--src/httpserver.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/httpserver.cpp b/src/httpserver.cpp
index e00c68585e..022703e79d 100644
--- a/src/httpserver.cpp
+++ b/src/httpserver.cpp
@@ -143,7 +143,8 @@ static std::vector<CSubNet> rpc_allow_subnets;
//! Work queue for handling longer requests off the event loop thread
static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr};
//! Handlers for (sub)paths
-static std::vector<HTTPPathHandler> pathHandlers;
+static Mutex g_httppathhandlers_mutex;
+static std::vector<HTTPPathHandler> pathHandlers GUARDED_BY(g_httppathhandlers_mutex);
//! Bound listening sockets
static std::vector<evhttp_bound_socket *> boundSockets;
@@ -244,6 +245,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
// Find registered handler for prefix
std::string strURI = hreq->GetURI();
std::string path;
+ LOCK(g_httppathhandlers_mutex);
std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin();
std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end();
for (; i != iend; ++i) {
@@ -642,11 +644,13 @@ HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod() const
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
{
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
+ LOCK(g_httppathhandlers_mutex);
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
}
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
{
+ LOCK(g_httppathhandlers_mutex);
std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin();
std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end();
for (; i != iend; ++i)