1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-30 14:10:59 +01:00

Detect symlink cycles

This commit is contained in:
Eelco Dolstra 2022-05-18 23:09:12 +02:00
parent 593798b2a0
commit df713a5d25
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 8 additions and 0 deletions

View file

@ -289,10 +289,14 @@ SourcePath SourcePath::resolveSymlinks() const
{
CanonPath res("/");
int linksAllowed = 1024;
for (auto & component : path) {
res.push(component);
while (true) {
if (auto st = accessor.maybeLstat(res)) {
if (!linksAllowed--)
throw Error("infinite symlink recursion in path '%s'", path);
if (st->type != InputAccessor::tSymlink) break;
auto target = accessor.readLink(res);
if (hasPrefix(target, "/"))