Skip to content

RUST-1881 Check integer conversions #1045

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

Merged
merged 3 commits into from
Mar 13, 2024

Conversation

abr-egn
Copy link
Contributor

@abr-egn abr-egn commented Mar 8, 2024

RUST-1881

This vendors the Checked type from https://github.com/zeta12ti/Checked, minus the num_traits support, plus a few conveniences for our specific error type, and uses it to check both integer conversions and integer arithmetic for particularly sensitive values like buffer sizes. The guidelines I used for this:

  • at function boundaries, sizes should be represented as usize
  • within a function, sizes should be Checked<usize> starting at the earliest possible point (ideally, initialization from a constant or single value), and persisting as late as possible so that all arithmetic is also checked.
  • deadlines (number of seconds/millis) can saturate in conversion
  • where context doesn't provide an easy way to propagate a Result, unwrap is used on the grounds that a crash is better than silent bad behavior

I added a lint for risky as conversions to the toplevel lib.rs so future uses will get caught :)

(Once this goes in I will, of course, cherry-pick this into 2.8.x.)

@abr-egn abr-egn requested a review from isabelatkinson March 8, 2024 18:28
@kevinAlbs kevinAlbs changed the title SECBUG-228 Check integer conversions RUST-1881 Check integer conversions Mar 12, 2024
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.

2 participants