You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2026/09/02 22:20:30 UTC

(trafficserver) branch master updated: Fix use-after-move in ConfigRegistry::do_register (#13622)

This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 4fe8ba67e0 Fix use-after-move in ConfigRegistry::do_register (#13622)
4fe8ba67e0 is described below

commit 4fe8ba67e048b3f4d5dcf155087eea88cc2f3796
Author: Brian Neradt <br...@gmail.com>
AuthorDate: Wed Sep 2 17:20:24 2026 -0500

    Fix use-after-move in ConfigRegistry::do_register (#13622)
    
    std::unordered_map::emplace may construct its node before discovering
    the key is already present, consuming the moved-from Entry even though
    nothing was inserted. The duplicate-registration warning then read
    plugin_name out of that gutted Entry and reported the incoming owner as
    "core". try_emplace leaves the argument untouched when the key exists,
    so the warning can name the registration it rejected.
    
    The read after the move came in with #13146, so the clang-analyzer job's
    Clang-Tidy stage (bugprone-use-after-move) now fails on master.
    
    Co-authored-by: Claude Opus 5 <no...@anthropic.com>
---
 src/mgmt/config/ConfigRegistry.cc | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/mgmt/config/ConfigRegistry.cc b/src/mgmt/config/ConfigRegistry.cc
index eb8fc3926a..49330d301b 100644
--- a/src/mgmt/config/ConfigRegistry.cc
+++ b/src/mgmt/config/ConfigRegistry.cc
@@ -217,7 +217,7 @@ ConfigRegistry::do_register(Entry entry)
       entry.trigger_records.size());
 
   std::unique_lock lock(_mutex);
-  auto [it, inserted] = _entries.emplace(entry.key, std::move(entry));
+  auto [it, inserted] = _entries.try_emplace(entry.key, std::move(entry));
 
   if (inserted) {
     setup_triggers(it->second);
@@ -238,9 +238,7 @@ ConfigRegistry::do_register(Entry entry)
   } else {
     auto const &existing       = it->second;
     char const *existing_owner = existing.plugin_name.empty() ? "core" : existing.plugin_name.c_str();
-    char const *incoming_owner = entry.plugin_name.empty() ? "core" : entry.plugin_name.c_str();
-    Warning("Config '%s' already registered by %s; ignoring registration from %s", it->first.c_str(), existing_owner,
-            incoming_owner);
+    Warning("Config '%s' already registered by %s; ignoring registration from %s", it->first.c_str(), existing_owner, owner_str);
   }
 
   return inserted;