From 847d98ad96e3d743fb42f12e4bb9db815dce2efc Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 27 Nov 2024 09:35:51 +0100 Subject: [PATCH] rec: prevent a data race: don't modify a global table on reload zones Including assert to prevent future accidents and detect more instances of current abuse. --- pdns/dnsparser.cc | 2 ++ pdns/dnsparser.hh | 8 ++++++++ pdns/recursordist/rec-main.cc | 4 ++-- pdns/recursordist/reczones.cc | 3 --- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index 1eecaea630..be08f2b68a 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -27,6 +27,8 @@ #include "namespaces.hh" #include "noinitvector.hh" +bool DNSRecordContent::d_locked{false}; + UnknownRecordContent::UnknownRecordContent(const string& zone) { // parse the input diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 07660b90ea..556d6eb14f 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -234,6 +234,7 @@ public: static void regist(uint16_t cl, uint16_t ty, makerfunc_t* f, zmakerfunc_t* z, const char* name) { + assert(!d_locked); if(f) getTypemap()[pair(cl,ty)]=f; if(z) @@ -245,6 +246,7 @@ public: static void unregist(uint16_t cl, uint16_t ty) { + assert(!d_locked); auto key = pair(cl, ty); getTypemap().erase(key); getZmakermap().erase(key); @@ -284,6 +286,11 @@ public: virtual uint16_t getType() const = 0; + static void lock() + { + d_locked = true; + } + protected: typedef std::map, makerfunc_t* > typemap_t; typedef std::map, zmakerfunc_t* > zmakermap_t; @@ -293,6 +300,7 @@ protected: static t2namemap_t& getT2Namemap(); static n2typemap_t& getN2Typemap(); static zmakermap_t& getZmakermap(); + static bool d_locked; }; struct DNSRecord diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 8c750d25a8..3e09545703 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -3153,8 +3153,8 @@ int main(int argc, char** argv) g_argc = argc; g_argv = argv; versionSetProduct(ProductRecursor); - reportBasicTypes(); - reportOtherTypes(); + reportAllTypes(); + DNSRecordContent::lock(); int ret = EXIT_SUCCESS; diff --git a/pdns/recursordist/reczones.cc b/pdns/recursordist/reczones.cc index ae48402db4..f015b9dde2 100644 --- a/pdns/recursordist/reczones.cc +++ b/pdns/recursordist/reczones.cc @@ -570,9 +570,6 @@ std::tuple, std::shared_ptr> { auto log = g_slog->withName("config"); - TXTRecordContent::report(); - OPTRecordContent::report(); - auto newMap = std::make_shared(); auto newSet = std::make_shared(); -- 2.47.2