Audit for write_bytes#1102
Merged
adpaco-aws merged 8 commits intomodel-checking:mainfrom Apr 26, 2022
Merged
Conversation
danielsn
approved these changes
Apr 25, 2022
Contributor
danielsn
left a comment
There was a problem hiding this comment.
Looks good, a couple comments
| align, | ||
| PropertyClass::DefaultAssertion, | ||
| "`dst` is properly aligned", | ||
| loc.clone(), |
Contributor
There was a problem hiding this comment.
No need to clone locations
| ); | ||
| let layout = self.layout_of(ty); | ||
| let sz = Expr::int_constant(layout.size.bytes(), Type::size_t()); | ||
| let memset_call = BuiltinFn::Memset.call(vec![dst, val, count.mul(sz)], loc); |
Contributor
There was a problem hiding this comment.
We have overflow checking on, right? So we'll see if this overflows?
Contributor
Author
There was a problem hiding this comment.
I checked it but we were not detecting overflows here. Updated to include an explicit overflow check for this computation. Added another test to check overflows.
| Stmt::block(vec![align_check, expr], loc) | ||
| } | ||
|
|
||
| /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to `val` |
Contributor
There was a problem hiding this comment.
Like the callout to the documentation
danielsn
approved these changes
Apr 26, 2022
Comment on lines
+1182
to
+1191
| // Check that computing `bytes` would not overflow | ||
| let layout = self.layout_of(ty); | ||
| let size = Expr::int_constant(layout.size.bytes(), Type::size_t()); | ||
| let bytes = count.mul_overflow(size); | ||
| let overflow_check = self.codegen_assert( | ||
| bytes.overflowed.not(), | ||
| PropertyClass::ArithmeticOverflow, | ||
| format!("{}: attempt to compute `bytes` which would overflow", intrinsic).as_str(), | ||
| loc, | ||
| ); |
Contributor
There was a problem hiding this comment.
Not for this PR, but we've done this check > 1 times, which means a helper fn might be good
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes:
Moves and updates the
write_bytesintrinsic implementation with an alignment check that it was missing. Adds 3 tests cases (2 of them inexpected).Resolved issues:
Part of #727
Call-outs:
Testing:
How is this change tested? Adds 3 tests.
Is this a refactor change? No.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.