Skip to content

coerceToString can overflow the stack, the bad way #10240

Open
@roberth

Description

@roberth

Describe the bug

Haven't spotted this in the wild, but:

nix-repl> let x = { outPath = x; }; in "${x}"
error: stack overflow (possible infinite recursion)

Of course here there's little a trace would add, but a real-world case doesn't have the luxury of a single line.

Steps To Reproduce

As above. Maybe add some fluff to make it realistic.

Expected behavior

Print positions, stack trace. Leverage the language call stack #9617
Perhaps use a different counter, because these are technically not calls in the language.
Tail recursion or a loop seem feasible, but over-engineered, and a limit is desirable in practice.

nix-env --version output

2.21

Additional context

Any C++-level recursion is susceptible. It'd be great to audit the code base using a static analysis tool. Doesn't have to run in CI in my opinion, so a tool with false positives is ok.

Priorities

Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugerror-messagesConfusing messages and better diagnosticslanguageThe Nix expression language; parser, interpreter, primops, evaluation, etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions