fix(libstore-tests): remove use-after-free bug for StringSource#11813
fix(libstore-tests): remove use-after-free bug for StringSource#11813Mic92 merged 1 commit intoNixOS:masterfrom xokdvium:dev/fix-use-after-free-libstore-tests
StringSource#11813Conversation
Unfortunately `StringSource` class is very easy was very easy to misuse because the ctor took a plain `std::string_view` which has a bad habit of being implicitly convertible from an rvalue `std::string`. This lead to unintentional use-after-free bugs. This patch makes `StringSource` much harder to misuse by disabling the ctor from a `std::string &&` (but `const std::string &` is ok). Fix affected tests from libstore-tests. Reformat those tests with clangd's range formatting since the diff is tiny and it seems appropriate.
|
@mergify queue |
🛑 The pull request has been merged manuallyDetailsThe pull request has been merged manually at 2ef5e22 |
|
Now that we have proper meson support enabling asan/ubsan should be much easier. |
|
@Mic92 There's already something akin to a tracking issue for sanitizers: #10969. In the meantime I'll try to compile the list of problems uncovered with sanitizers (and there are countless). Almost everything either leaks, has UB or commits memory crimes. Maybe a good approach would to be first enable only UBSAN and tackle everything it has to say. Addressing memory leaks and memory crimes would be a huge undertaking that deserves a tracking issue of its own. |
|
@xokdvium ok. Maybe add a list of errors you got to it and I might also work on some of them. |
…1813 fix(libstore-tests): remove use-after-free bug for `StringSource` (backport #11813)
Unfortunately
StringSourceclass is very easy was very easy to misuse because the ctor took a plainstd::string_viewwhich has a bad habit of being implicitly convertible from an rvaluestd::string. This lead to unintentional use-after-free bugs.This patch makes
StringSourcemuch harder to misuse by disabling the ctor from astd::string &&(butconst std::string &is ok).Fix affected tests from libstore-tests.
Reformat those tests with clangd's range formatting since the diff is tiny and it seems appropriate.
Motivation
Ran some tests under ASAN and UBSAN and got shocked by the amount of errors. This looks a good starting point for starting to untangle them.
Context
For reference here's the ASAN log for one of the two tests:
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.