aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMacroFake <falke.marco@gmail.com>2022-09-07 11:27:05 +0200
committerMacroFake <falke.marco@gmail.com>2022-09-07 11:27:10 +0200
commitfc44d1796e4df5824423d7d13de3082fe204db7d (patch)
tree199436bf7b091d2d3a99337baca163c59e03bf9a /src
parent124e75a41ea0f3f0e90b63b0c41813184ddce2ab (diff)
parent4296dde28757d88a7076847484669fb202b47bc8 (diff)
downloadbitcoin-fc44d1796e4df5824423d7d13de3082fe204db7d.tar.xz
Merge bitcoin/bitcoin#25983: Prevent data race for `pathHandlers`
4296dde28757d88a7076847484669fb202b47bc8 Prevent data race for `pathHandlers` (Hennadii Stepanov) Pull request description: Fixes bitcoin/bitcoin#19341. ACKs for top commit: ryanofsky: Code review ACK 4296dde28757d88a7076847484669fb202b47bc8. This should protect the vector. It also seems to make the http_request_cb callback single threaded, but that seems ok, since it is just adding work queue items not actually processing requests. Tree-SHA512: 1c3183100bbc80d8e83543da090b8f4521921cf30d444e3e4c87102bf7a1e67ccc4dfea7e9990ac49741b2a5708f259f4eced9d4049c20ae4e531461532a6aef
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 8e00a6278f..e68436cc2c 100644
--- a/src/httpserver.cpp
+++ b/src/httpserver.cpp
@@ -142,7 +142,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 GlobalMutex g_httppathhandlers_mutex;
+static std::vector<HTTPPathHandler> pathHandlers GUARDED_BY(g_httppathhandlers_mutex);
//! Bound listening sockets
static std::vector<evhttp_bound_socket *> boundSockets;
@@ -243,6 +244,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) {
@@ -674,11 +676,13 @@ std::optional<std::string> GetQueryParameterFromUri(const char* uri, const std::
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)