Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diff-closures: fix a use after free #11187

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/manual/src/language/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ Equivalent to `!`*b1* `||` *b2*.
> **Warning**
>
> This syntax is part of an
> [experimental feature](@docroot@/contributing/experimental-features.md)
> [experimental feature](@docroot@/development/experimental-features.md)
> and may change in future releases.
>
> To use this syntax, make sure the
> [`pipe-operators` experimental feature](@docroot@/contributing/experimental-features.md#xp-feature-pipe-operators)
> [`pipe-operators` experimental feature](@docroot@/development/experimental-features.md#xp-feature-pipe-operators)
> is enabled.
> For example, include the following in [`nix.conf`](@docroot@/command-ref/conf-file.md):
>
Expand Down
10 changes: 6 additions & 4 deletions src/nix/diff-closures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ GroupedPaths getClosureInfo(ref<Store> store, const StorePath & toplevel)

GroupedPaths groupedPaths;

for (auto & path : closure) {
for (auto const & path : closure) {
/* Strip the output name. Unfortunately this is ambiguous (we
can't distinguish between output names like "bin" and
version suffixes like "unstable"). */
static std::regex regex("(.*)-([a-z]+|lib32|lib64)");
std::smatch match;
std::string name(path.name());
std::cmatch match;
Copy link
Member

Choose a reason for hiding this comment

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

smatch might have been nice, but I don't see a way to make that work either. The std::regex does not seem to support it when the input is not an actual std::string. Unfortunate.

std::string name{path.name()};
std::string_view const origName = path.name();
std::string outputName;
if (std::regex_match(name, match, regex)) {

if (std::regex_match(origName.begin(), origName.end(), match, regex)) {
name = match[1];
outputName = match[2];
}
Expand Down
Loading