diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index c4a2b00af..4315f3335 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -378,6 +378,8 @@ static void getDerivations( Done & done, bool ignoreAssertionFailures) { + auto _level = state.addCallDepth(vIn.determinePos(noPos)); + Value v; state.autoCallFunction(autoArgs, vIn, v); diff --git a/tests/functional/simple.sh b/tests/functional/simple.sh index c1f2eef41..e284ec809 100755 --- a/tests/functional/simple.sh +++ b/tests/functional/simple.sh @@ -35,3 +35,8 @@ if test "$outPath" != "/foo/xxiwa5zlaajv6xdjynf9yym9g319d6mn-big-derivation-attr echo "big-derivation-attr.nix hash appears broken, got $outPath. Memory corruption in large drv attr?" exit 1 fi + +# Test that nix-instantiate on a deeply nested recurseForDerivations structure +# produces a controlled stack overflow error rather than a segfault. +expectStderr 1 nix-instantiate --expr 'let x = { recurseForDerivations = true; more = x; }; in x' \ + | grepQuiet "stack overflow; max-call-depth exceeded"