Skip to content

Fix use-after-move in ConfigRegistry::do_register - #13622

Merged
bneradt merged 1 commit into
apache:masterfrom
bneradt:fix-config-registry-use-after-move
Sep 2, 2026
Merged

Fix use-after-move in ConfigRegistry::do_register#13622
bneradt merged 1 commit into
apache:masterfrom
bneradt:fix-config-registry-use-after-move

Conversation

@bneradt

@bneradt bneradt commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot AI lite review requested due to automatic review settings September 2, 2026 20:50
@bneradt bneradt added this to the 11.0.0 milestone Sep 2, 2026
@bneradt bneradt self-assigned this Sep 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, standards-correct for try_emplace semantics, and directly eliminates the verified use-after-move scenario without altering registration behavior.

Pull request overview

Fixes a use-after-move in ConfigRegistry::do_register() when duplicate config registrations occur, ensuring the warning message reliably reports the incoming (rejected) registration owner.

Changes:

  • Replace _entries.emplace(...) with _entries.try_emplace(...) so the incoming Entry is not moved-from on duplicate keys.
  • Use a precomputed owner_str for the duplicate-registration warning to avoid reading owner information from a potentially moved-from Entry.
  • Add an in-code comment documenting why try_emplace is required here.
File summaries
File Description
src/mgmt/config/ConfigRegistry.cc Switches to try_emplace in do_register() to prevent consuming the incoming Entry on duplicates and to keep owner reporting correct.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bneradt
bneradt force-pushed the fix-config-registry-use-after-move branch from 933d3d3 to ab99330 Compare September 2, 2026 20:56
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 apache#13146, so the clang-analyzer job's
Clang-Tidy stage (bugprone-use-after-move) now fails on master.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bneradt
bneradt force-pushed the fix-config-registry-use-after-move branch from ab99330 to d016c90 Compare September 2, 2026 20:57
Copilot AI review requested due to automatic review settings September 2, 2026 20:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, correct for the reported emplace/move behavior, and the warning message now reliably uses a stable owner string.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@bryancall bryancall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. try_emplace is the right choice here, since it is the only one of the two that promises to leave the argument alone when the key is already present, and reading the owner from owner_str makes the rejected registration nameable again.

One non-blocking note: owner_str is captured before the move, so in the else branch it is a pointer into the local entry's string buffer, and it is valid only because try_emplace does not touch that argument. If this ever goes back to emplace, that read becomes a pointer into a moved-from string rather than the empty-string read it is today. A short comment on the try_emplace line noting that the warning below depends on it would make that harder to undo by accident.

@bneradt
bneradt merged commit 4fe8ba6 into apache:master Sep 2, 2026
15 checks passed
@bneradt
bneradt deleted the fix-config-registry-use-after-move branch September 2, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants