diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2018-09-17T14·36+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2018-09-17T14·36+0200 |
commit | 52f6d541b9f872568f0043a20accc847ce6d5412 (patch) | |
tree | ab30067db7f301bab9dc67ccc61e9cbc9bfe35d8 /src/nix-env | |
parent | 901dfc79788595f6382c8d8d9f584ec38a4cc010 (diff) |
nix-env: Fix segfault if -f argument is not a directory or a Nix expression
Fixes #2425.
Diffstat (limited to 'src/nix-env')
-rw-r--r-- | src/nix-env/nix-env.cc | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index a43b103f6ec6..f9c8a8d313e7 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -150,10 +150,8 @@ static void loadSourceExpr(EvalState & state, const Path & path, Value & v) if (stat(path.c_str(), &st) == -1) throw SysError(format("getting information about '%1%'") % path); - if (isNixExpr(path, st)) { + if (isNixExpr(path, st)) state.evalFile(path, v); - return; - } /* The path is a directory. Put the Nix expressions in the directory in a set, with the file name of each expression as @@ -161,13 +159,15 @@ static void loadSourceExpr(EvalState & state, const Path & path, Value & v) set flat, not nested, to make it easier for a user to have a ~/.nix-defexpr directory that includes some system-wide directory). */ - if (S_ISDIR(st.st_mode)) { + else if (S_ISDIR(st.st_mode)) { state.mkAttrs(v, 1024); state.mkList(*state.allocAttr(v, state.symbols.create("_combineChannels")), 0); StringSet attrs; getAllExprs(state, path, attrs, v); v.attrs->sort(); } + + else throw Error("path '%s' is not a directory or a Nix expression", path); } |