Skip to content

Mitigate a segmentation fault when a derivation has no name attribute#5127

Closed
fogti wants to merge 1 commit intoNixOS:masterfrom
fogti:iss5113
Closed

Mitigate a segmentation fault when a derivation has no name attribute#5127
fogti wants to merge 1 commit intoNixOS:masterfrom
fogti:iss5113

Conversation

@fogti
Copy link
Contributor

@fogti fogti commented Aug 12, 2021

Fixes #5113, but does not fix the underlying issue that the location data is not propagated early enough (it might fix the segmentation fault, tho).

@fogti
Copy link
Contributor Author

fogti commented Aug 13, 2021

@nixinator @happysalada could you try to test a nix with this patch applied on a derivation with a missing name attribute and post the resulting errors?

@happysalada
Copy link
Contributor

Thank you for this, I'll add it to the list of things to do on monday.

@happysalada
Copy link
Contributor

I confirmed that it works.
This is the error I now get.

error: attribute 'name' missing for call to 'derivationStrict'

       at //builtin/derivation.nix:9:12:

For anyone else, this can be tested in the following repo
https://github.com/ngi-nix/sonar/tree/0e1960d34a5c776e6f9e989d2ff0331524b7ccfc
Just trying to build the flake should segfault with current nixUnstable.

Thank you for the PR.

@fogti
Copy link
Contributor Author

fogti commented Aug 17, 2021

@edolstra could you please review/merge this?

@fogti fogti changed the title Try to partially mitigate a segmentation fault when a derivation has no name attribute Mitigate a segmentation fault when a derivation has no name attribute Aug 17, 2021
@fogti
Copy link
Contributor Author

fogti commented Aug 17, 2021

hm, maybe I should adjust the commit message to be more accurate.

original patch:

commit b03b02775299fc29334cb0eba0e6c64e632f534c (HEAD -> iss5113, zseri/iss5113)
Author: zseri <[email protected]>
Date:   Thu Aug 12 16:25:22 2021 +0200

    Try to partially mitigate a segmentation fault in libnixexpr.so when a derivation has no name attribute

diff --git a/src/libexpr/attr-set.hh b/src/libexpr/attr-set.hh
index 1da8d91df..2550ad032 100644
--- a/src/libexpr/attr-set.hh
+++ b/src/libexpr/attr-set.hh
@@ -41,7 +41,7 @@ private:
     size_t size_, capacity_;
     Attr attrs[0];
 
-    Bindings(size_t capacity) : size_(0), capacity_(capacity) { }
+    Bindings(size_t capacity) : pos(&noPos), size_(0), capacity_(capacity) { }
     Bindings(const Bindings & bindings) = delete;
 
 public:

…no name attribute

This may not fix the underlying issue that the location data is not propagated early enough.
@Ma27
Copy link
Member

Ma27 commented Aug 26, 2021

Seems related to #4895.

@fogti
Copy link
Contributor Author

fogti commented Aug 27, 2021

yes.

roberth added a commit to hercules-ci/nix that referenced this pull request Aug 29, 2021
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
@roberth
Copy link
Member

roberth commented Aug 29, 2021

#5192 incorporates both and uses types to prevent it in the future.

@fogti fogti deleted the iss5113 branch August 30, 2021 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

segmentation fault in libnixexpr.so when derivation has no name attribute

5 participants