mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
Merge pull request #14111 from Mic92/symlinks
Prevent infinite symlink loop in followLinksToStore()
This commit is contained in:
commit
f816b9bcb8
1 changed files with 10 additions and 0 deletions
|
|
@ -58,12 +58,22 @@ std::pair<StorePath, Path> StoreDirConfig::toStorePath(PathView path) const
|
|||
Path Store::followLinksToStore(std::string_view _path) const
|
||||
{
|
||||
Path path = absPath(std::string(_path));
|
||||
|
||||
// Limit symlink follows to prevent infinite loops
|
||||
unsigned int followCount = 0;
|
||||
const unsigned int maxFollow = 1024;
|
||||
|
||||
while (!isInStore(path)) {
|
||||
if (!std::filesystem::is_symlink(path))
|
||||
break;
|
||||
|
||||
if (++followCount >= maxFollow)
|
||||
throw Error("too many symbolic links encountered while resolving '%s'", _path);
|
||||
|
||||
auto target = readLink(path);
|
||||
path = absPath(target, dirOf(path));
|
||||
}
|
||||
|
||||
if (!isInStore(path))
|
||||
throw BadStorePath("path '%1%' is not in the Nix store", path);
|
||||
return path;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue