Skip to content

Commit

Permalink
Properly return false on builtins.pathExists /someNonAllowedPath
Browse files Browse the repository at this point in the history
Follow-up from #5807 to fix #5807 (comment)
  • Loading branch information
thufschmitt committed Dec 23, 2021
1 parent 7feb741 commit 0dcd8c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,9 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
path, e.path),
.errPos = pos
});
} catch (RestrictedPathError & e) {
mkBool(v, false);
return;
}

try {
Expand All @@ -1387,8 +1390,6 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
/* Don't give away info from errors while canonicalising
‘path’ in restricted mode. */
mkBool(v, false);
} catch (RestrictedPathError & e) {
mkBool(v, false);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/pure-eval.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ missingImpureErrorMsg=$(! nix eval --expr 'builtins.readFile ./pure-eval.sh' 2>&
echo "$missingImpureErrorMsg" | grep -q -- --impure || \
fail "The error message should mention the “--impure” flag to unblock users"

[[ $(nix eval --expr 'builtins.pathExists ./pure-eval.sh') == false ]] || \
fail "Calling 'pathExists' on a non-authorised path should return false"

(! nix eval --expr builtins.currentTime)
(! nix eval --expr builtins.currentSystem)

Expand Down

0 comments on commit 0dcd8c2

Please sign in to comment.