Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/networkd: fix range assertions on 32 bit Nix #45722

Merged
merged 1 commit into from Aug 28, 2018

Conversation

lopsided98
Copy link
Contributor

Motivation for this change

Range assertions were recently added to the networkd module that exceeded the range of a signed 32-bit int, breaking the module on 32 bit Nix.

Things done

This PR changes those assertions to checks that the value is an int, as suggested in #44233 (comment).

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

Copy link
Contributor

@xeji xeji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep checking ranges but choose the upper bound depending on the platform.

assertInt = name: group: attr:
optional (attr ? ${name} && !isInt attr.${name})
"Systemd ${group} field `${name}' is not an integer";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isInt allows any integer, even negative, so this significantly weakens the assertion too much.
You should keep checking for a range with assertRange but replace the hardcoded upper bound 4294967295 with the largest positive integer depending on the platform's bitsize.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just checking if it is larger then 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case there may be a simpler solution: just check for isInt and the lower bound , so you don't have to specify the upper bound.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(guess we were writing in parallel 😄)

@lopsided98
Copy link
Contributor Author

I added checks that the value is >= 0. I also kept the isInt assertions, since the value should be an integer. There are a number of assertRange checks that should probably have an int check as well, but currently do not.

Also, if NixOS/nix#2378 is merged, this PR would no longer be necessary.

@xeji
Copy link
Contributor

xeji commented Aug 28, 2018

Thanks. Nitpick: When the lower bound was 1 before, you should (assertMinimum 1) not 0.
Just to keep the behavior unchanged.

@lopsided98
Copy link
Contributor Author

Oops, fixed.

Copy link
Contributor

@xeji xeji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants