-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix segfault on infinite recursion in some cases
This fixes a segfault on infinite function call recursion (rather than infinite thunk recursion) by tracking the function call depth in `EvalState`. Additionally, to avoid printing extremely long stack traces, stack frames are now deduplicated, with a `(19997 duplicate traces omitted)` message. This should only really be triggered in infinite recursion scenarios. Before: $ nix-instantiate --eval --expr '(x: x x) (x: x x)' Segmentation fault: 11 After: $ nix-instantiate --eval --expr '(x: x x) (x: x x)' error: stack overflow at «string»:1:14: 1| (x: x x) (x: x x) | ^ $ nix-instantiate --eval --expr '(x: x x) (x: x x)' --show-trace error: … from call site at «string»:1:1: 1| (x: x x) (x: x x) | ^ … while calling anonymous lambda at «string»:1:2: 1| (x: x x) (x: x x) | ^ … from call site at «string»:1:5: 1| (x: x x) (x: x x) | ^ … while calling anonymous lambda at «string»:1:11: 1| (x: x x) (x: x x) | ^ … from call site at «string»:1:14: 1| (x: x x) (x: x x) | ^ (19997 duplicate traces omitted) error: stack overflow at «string»:1:14: 1| (x: x x) (x: x x) | ^
- Loading branch information
Showing
12 changed files
with
358 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
synopsis: Some stack overflow segfaults are fixed | ||
issues: 9616 | ||
prs: 9617 | ||
--- | ||
|
||
The number of nested function calls has been restricted, to detect and report | ||
infinite function call recursions. The default maximum call depth is 10,000 and | ||
can be set with [the `max-call-depth` | ||
option](@docroot@/command-ref/conf-file.md#conf-max-call-depth). | ||
|
||
This fixes segfaults or the following unhelpful error message in many cases: | ||
|
||
error: stack overflow (possible infinite recursion) | ||
|
||
Before: | ||
|
||
``` | ||
$ nix-instantiate --eval --expr '(x: x x) (x: x x)' | ||
Segmentation fault: 11 | ||
``` | ||
|
||
After: | ||
|
||
``` | ||
$ nix-instantiate --eval --expr '(x: x x) (x: x x)' | ||
error: stack overflow | ||
at «string»:1:14: | ||
1| (x: x x) (x: x x) | ||
| ^ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error: | ||
… from call site | ||
at /pwd/lang/eval-fail-duplicate-traces.nix:9:3: | ||
8| in | ||
9| throwAfter 2 | ||
| ^ | ||
10| | ||
|
||
… while calling 'throwAfter' | ||
at /pwd/lang/eval-fail-duplicate-traces.nix:4:16: | ||
3| let | ||
4| throwAfter = n: | ||
| ^ | ||
5| if n > 0 | ||
|
||
… from call site | ||
at /pwd/lang/eval-fail-duplicate-traces.nix:6:10: | ||
5| if n > 0 | ||
6| then throwAfter (n - 1) | ||
| ^ | ||
7| else throw "Uh oh!"; | ||
|
||
… while calling 'throwAfter' | ||
at /pwd/lang/eval-fail-duplicate-traces.nix:4:16: | ||
3| let | ||
4| throwAfter = n: | ||
| ^ | ||
5| if n > 0 | ||
|
||
… from call site | ||
at /pwd/lang/eval-fail-duplicate-traces.nix:6:10: | ||
5| if n > 0 | ||
6| then throwAfter (n - 1) | ||
| ^ | ||
7| else throw "Uh oh!"; | ||
|
||
… while calling 'throwAfter' | ||
at /pwd/lang/eval-fail-duplicate-traces.nix:4:16: | ||
3| let | ||
4| throwAfter = n: | ||
| ^ | ||
5| if n > 0 | ||
|
||
error: Uh oh! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Check that we only omit duplicate stack traces when there's a bunch of them. | ||
# Here, there's only a couple duplicate entries, so we output them all. | ||
let | ||
throwAfter = n: | ||
if n > 0 | ||
then throwAfter (n - 1) | ||
else throw "Uh oh!"; | ||
in | ||
throwAfter 2 |
38 changes: 38 additions & 0 deletions
38
tests/functional/lang/eval-fail-infinite-recursion-lambda.err.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
error: | ||
… from call site | ||
at /pwd/lang/eval-fail-infinite-recursion-lambda.nix:1:1: | ||
1| (x: x x) (x: x x) | ||
| ^ | ||
2| | ||
|
||
… while calling anonymous lambda | ||
at /pwd/lang/eval-fail-infinite-recursion-lambda.nix:1:2: | ||
1| (x: x x) (x: x x) | ||
| ^ | ||
2| | ||
|
||
… from call site | ||
at /pwd/lang/eval-fail-infinite-recursion-lambda.nix:1:5: | ||
1| (x: x x) (x: x x) | ||
| ^ | ||
2| | ||
|
||
… while calling anonymous lambda | ||
at /pwd/lang/eval-fail-infinite-recursion-lambda.nix:1:11: | ||
1| (x: x x) (x: x x) | ||
| ^ | ||
2| | ||
|
||
… from call site | ||
at /pwd/lang/eval-fail-infinite-recursion-lambda.nix:1:14: | ||
1| (x: x x) (x: x x) | ||
| ^ | ||
2| | ||
|
||
(19997 duplicate frames omitted) | ||
|
||
error: stack overflow; max-call-depth exceeded | ||
at /pwd/lang/eval-fail-infinite-recursion-lambda.nix:1:14: | ||
1| (x: x x) (x: x x) | ||
| ^ | ||
2| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(x: x x) (x: x x) |
Oops, something went wrong.