avoid null pointer dereference when attrSet->pos is null#4895
avoid null pointer dereference when attrSet->pos is null#4895manveru wants to merge 1 commit intoNixOS:masterfrom
Conversation
e833200 to
f93d30d
Compare
thufschmitt
left a comment
There was a problem hiding this comment.
Thanks for the fix!
I have a couple of comments to clean this a slight bit, but overall 👍🏻
src/libexpr/primops.cc
Outdated
|
|
||
| Pos aPos = *attrSet->pos; | ||
| if (aPos == noPos) { | ||
| if (attrSet->pos == nullptr) { |
There was a problem hiding this comment.
This might be factored out a slight bit I guess. Something along the lines of:
if (attrSet->pos && *attrSet->pos != noPos) {
// Throw with the right location and the stack trace
} else {
// Throw with the parent location
}There was a problem hiding this comment.
Does this look OK to you now?
tests/list-to-attrs-nullptr.sh
Outdated
| @@ -0,0 +1,7 @@ | |||
| #!/usr/bin/env bash | |||
There was a problem hiding this comment.
Rather than adding a brand new toplevel test (which does cost a bit as initializing a test is slightly expensive), I think you can
- Add this to
tests/lang/eval-fail-list-to-attrs.nix - Change https://github.com/NixOS/nix/blob/master/tests/lang.sh#L35 to
if ! expect 1 nix-instantiate --eval lang/$i.nix; then(I checked, all the other tests do return1as they should)
Also: Can you add a reference to the issue in the test file, so that we know why it’s here?
|
Thanks for all the guidance :) |
|
I've run cc @edolstra |
|
I plan to merge this in a few days unless someone raises a concern. |
|
@domenkozar I want to have a look at it first. |
|
The majority of other sites where Meanwhile, it doesn't hurt to merge this. |
Couldn’t we make
IIRC in the current case, we explicitly pass a |
Ma27
left a comment
There was a problem hiding this comment.
This fixes a fairly weird problem I had when forgetting to pass version (along with pname) to buildRustPackage in an overlay evaluated by a flake.
|
@edolstra This change is an improvement. Could you merge it? |
1e41462 to
11dbec4
Compare
|
Did another rebase and squashed the commits to make this hopefully a bit more attractive to merge :) |
|
@edolstra would be awesome to see this merged :) |
This fixes a class of crashes and introduces ptr<T> to make the code robust against this failure mode going forward. Thanks regnat for the idea of a ref<T> without overhead! Closes NixOS#4895 Closes NixOS#4893 Closes NixOS#5127 Closes NixOS#5113
|
There's #5192 now, which builds on the ideas from this PR and is more thorough. |
|
Awesome, that looks way better! |
This may be a fix for #4893
I added a small test that just checks for the segfault, given that
builtins.tryEvalcannot catch this kind of error.To recap, here's the behavior before:
And after the fix: