mirror of
https://github.com/NixOS/nix
synced 2025-07-07 18:31:49 +02:00
Detect symlink cycles
This commit is contained in:
parent
593798b2a0
commit
df713a5d25
2 changed files with 8 additions and 0 deletions
|
@ -289,10 +289,14 @@ SourcePath SourcePath::resolveSymlinks() const
|
||||||
{
|
{
|
||||||
CanonPath res("/");
|
CanonPath res("/");
|
||||||
|
|
||||||
|
int linksAllowed = 1024;
|
||||||
|
|
||||||
for (auto & component : path) {
|
for (auto & component : path) {
|
||||||
res.push(component);
|
res.push(component);
|
||||||
while (true) {
|
while (true) {
|
||||||
if (auto st = accessor.maybeLstat(res)) {
|
if (auto st = accessor.maybeLstat(res)) {
|
||||||
|
if (!linksAllowed--)
|
||||||
|
throw Error("infinite symlink recursion in path '%s'", path);
|
||||||
if (st->type != InputAccessor::tSymlink) break;
|
if (st->type != InputAccessor::tSymlink) break;
|
||||||
auto target = accessor.readLink(res);
|
auto target = accessor.readLink(res);
|
||||||
if (hasPrefix(target, "/"))
|
if (hasPrefix(target, "/"))
|
||||||
|
|
|
@ -29,3 +29,7 @@ nix-instantiate --eval -E 'assert 1 + 2 == 3; true'
|
||||||
[[ $(nix-instantiate -A attr --eval "./eval.nix") == '{ foo = "bar"; }' ]]
|
[[ $(nix-instantiate -A attr --eval "./eval.nix") == '{ foo = "bar"; }' ]]
|
||||||
[[ $(nix-instantiate -A attr --eval --json "./eval.nix") == '{"foo":"bar"}' ]]
|
[[ $(nix-instantiate -A attr --eval --json "./eval.nix") == '{"foo":"bar"}' ]]
|
||||||
[[ $(nix-instantiate -A int --eval - < "./eval.nix") == 123 ]]
|
[[ $(nix-instantiate -A int --eval - < "./eval.nix") == 123 ]]
|
||||||
|
|
||||||
|
# Check that symlink cycles don't cause a hang.
|
||||||
|
ln -sfn cycle.nix $TEST_ROOT/cycle.nix
|
||||||
|
(! nix eval --file $TEST_ROOT/cycle.nix)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue