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

Avoid accessing uninitialized settings in own init #11117

Merged
merged 1 commit into from
Jul 17, 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
10 changes: 4 additions & 6 deletions src/libexpr/eval-settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ EvalSettings::EvalSettings(bool & readOnlyMode, EvalSettings::LookupPathHooks lo
builtinsAbortOnWarn = true;
}

Strings EvalSettings::getDefaultNixPath() const
Strings EvalSettings::getDefaultNixPath()
{
Strings res;
auto add = [&](const Path & p, const std::string & s = std::string()) {
Expand All @@ -69,11 +69,9 @@ Strings EvalSettings::getDefaultNixPath() const
}
};

if (!restrictEval && !pureEval) {
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't aware how problematic this conditional was, but in my mental model it was always initialized to those three elements anyway, because we looked at it from the perspective of the initialization of the settings object anyway, of which we were aware that it was not in a properly loaded state yet. But yeah, it's worse; not even properly initialized, but in effect it doesn't matter which it is.

off-topic: I'd much prefer a good ol' infinite recursion over this stateful mess :D

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, an option would be to make all settings (virtual) methods, such that they can compute.

Copy link
Member

Choose a reason for hiding this comment

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

That'd be alright, and a call depth limit could replace tBlackhole in this comparison.

add(getNixDefExpr() + "/channels");
add(rootChannelsDir() + "/nixpkgs", "nixpkgs");
add(rootChannelsDir());
}
add(getNixDefExpr() + "/channels");
add(rootChannelsDir() + "/nixpkgs", "nixpkgs");
add(rootChannelsDir());

return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-settings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct EvalSettings : Config

bool & readOnlyMode;

Strings getDefaultNixPath() const;
static Strings getDefaultNixPath();

static bool isPseudoUrl(std::string_view s);

Expand Down
Loading