Skip to content

libexpr: Fix invalid handling of errors for imported functions#13450

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
xokdvium:formal-call-unreachable
Jul 11, 2025
Merged

libexpr: Fix invalid handling of errors for imported functions#13450
Ericson2314 merged 1 commit intoNixOS:masterfrom
xokdvium:formal-call-unreachable

Conversation

@xokdvium
Copy link
Contributor

Motivation

c39cc00 has added assertions for all Value accesses and the following case has started failing with an unreachable:

(/tmp/fun.nix):

{a}: a
$ nix eval --impure --expr 'import /tmp/fun.nix {a="a";b="b";}'

This would crash:

terminating due to unexpected unrecoverable internal error: Unexpected condition in getStorage at ../include/nix/expr/value.hh:844

This is not a regression, but rather surfaces an existing problem, which previously was left undiagnosed. In the case of an import fun is the import primOp, so that read is invalid and previously this resulted in an access into an inactive union member, which is UB. The correct thing to use is vCur. Identical problem also affected the case of a missing argument.

Add previously failing test cases to the functional/lang test suite.

Context

Fixes #13448.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

c39cc00 has added assertions for
all Value accesses and the following case has started failing with
an `unreachable`:

(/tmp/fun.nix):

```nix
{a}: a
```

```
$ nix eval --impure --expr 'import /tmp/fun.nix {a="a";b="b";}'
```

This would crash:

```
terminating due to unexpected unrecoverable internal error: Unexpected condition in getStorage at ../include/nix/expr/value.hh:844
```

This is not a regression, but rather surfaces an existing problem, which previously
was left undiagnosed. In the case of an import `fun` is the `import` primOp, so that read is invalid
and previously this resulted in an access into an inactive union member, which is UB.
The correct thing to use is `vCur`. Identical problem also affected the case of a missing argument.

Add previously failing test cases to the functional/lang test suite.

Fixes NixOS#13448.
@xokdvium xokdvium requested a review from edolstra as a code owner July 11, 2025 17:31
@xokdvium xokdvium self-assigned this Jul 11, 2025
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Jul 11, 2025
@xokdvium xokdvium requested review from Ericson2314 and roberth July 11, 2025 17:32
@xokdvium xokdvium added backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backport 2.30-maintenance Automatically creates a PR against the branch labels Jul 11, 2025
@edolstra
Copy link
Member

Oops, I fixed this a while ago in the multithreaded evaluator (5310b0f), sorry for not backporting it.

xokdvium added a commit that referenced this pull request Jul 11, 2025
…3450

libexpr: Fix invalid handling of errors for imported functions (backport #13450)
xokdvium added a commit that referenced this pull request Jul 11, 2025
…3450

libexpr: Fix invalid handling of errors for imported functions (backport #13450)
@xokdvium xokdvium deleted the formal-call-unreachable branch July 11, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backport 2.30-maintenance Automatically creates a PR against the branch with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coredump in nix 2.30.0

3 participants