brbzull0 opened a new pull request, #13907: URL: https://github.com/apache/trafficserver/pull/13907
`ConfigRegistry::do_register()` inserts with `_entries.try_emplace(entry.key, std::move(entry))`. The key argument is a reference into the `Entry` that the same call moves from, and Coverity reports that as a use after move. libstdc++ 16 and libc++ 21 copy the key into the new node before they move-construct the value, and leave both arguments untouched when the key is already present, so today the key is read before the move. The call still relies on that order inside the library. #13622 switched this line from `emplace` to `try_emplace` so that the duplicate-registration warning names the registration it rejected. Coverity CID: [1685941](https://scan6.scan.coverity.com/#/project-view/58063/10191?selectedIssue=1685941) **What changes:** - `do_register()` copies the key into a local before it takes the lock, and passes `std::move(key), std::move(entry)` to `try_emplace`, so the key argument refers to a separate string rather than into the object being moved. A new key is stored as before. On a duplicate key `try_emplace` leaves both arguments untouched, so the warning reads the rejected registration's plugin name as it did before. - New test "ConfigRegistry duplicate-key warning names both owners" in `src/records/unit_tests/test_ConfigRegistry.cc`, for a plugin over a plugin, a core over a plugin and a plugin over core. It checks: - the warning text, key and both owners included; - that the rejected plugin registration returns false; - that the stored entry keeps its key and its first owner. **What this PR does not do:** - It does not change behaviour on the libraries above; it removes the aliasing Coverity points at. - The new test does not catch a return to `emplace` with these libraries: their `emplace(key, value)` also looks the key up before building a node. It fails when the registration is moved from before the duplicate check, for example through `insert(std::make_pair(...))`. - A rejected duplicate now copies its key once more. Registration runs at startup and plugin init. - It does not touch the 10.2.x branch, which still calls `emplace(entry.key, std::move(entry))` because the earlier fix was not backported there. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
