Skip to content
Snippets Groups Projects
Commit d89d9958 authored by Dima's avatar Dima
Browse files

bugfix: Adding depth limit to resolveExprPath

There is no termination condition for evaluation of cyclical
expression paths which can lead to infinite loops. This addresses
one spot in the parser in a similar fashion as utils.cc/canonPath
does.

This issue can be reproduced by something like:

```
ln -s a b
ln -s b a

nix-instantiate -E 'import ./a'
```
parent 3e787423
No related branches found
No related tags found
No related merge requests found
......@@ -576,10 +576,15 @@ Path resolveExprPath(Path path)
{
assert(path[0] == '/');
unsigned int followCount = 0, maxFollow = 1024;
/* If `path' is a symlink, follow it. This is so that relative
path references work. */
struct stat st;
while (true) {
// Basic cycle/depth limit to avoid infinite loops.
if (++followCount >= maxFollow)
throw Error(format("can't resolve expression. infinite symlink recursion in path '%1%'") % path);
if (lstat(path.c_str(), &st))
throw SysError(format("getting status of '%1%'") % path);
if (!S_ISLNK(st.st_mode)) break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment