Code quality fixes including fix for undefined behavior in Message::with_size and <Message as From<&[u8]>>::from#403
Open
antonilol wants to merge 7 commits intoerickt:masterfrom
Open
Code quality fixes including fix for undefined behavior in Message::with_size and <Message as From<&[u8]>>::from#403antonilol wants to merge 7 commits intoerickt:masterfrom
antonilol wants to merge 7 commits intoerickt:masterfrom
Conversation
including: - replace `str::from_utf8(cstr.to_bytes())` with `cstr.to_str()` - remove unnecessary `as` casts (numeric and pointer) - remove unused import `std::str`, not detected by rustc because of a bug
- added PartialOrd, Ord, Clone, Default and Hash - moved PartialEq and Eq from between Deref and DerefMut
…y as_mut_ptr through DerefMut - add `as_ptr` and `as_mut_ptr`, these methods create no intermediate reference, previously these methods from `&mut [u8]` (or `&[u8]`) would be used, which is ub if the data is uninitialized. - use `ptr::slice_from_raw_parts_mut` when dropping a contained Box in a message to not create an intermediate reference to its contents. if this is ub, this has now been fixed. also, explicitly dropping here better expressed the goal of this function. - add methods to get the raw pointer of a Message, and get the length of the bytes without creating an intermediate reference.
Author
|
Lines 78 to 84 in 4b873ae This safety comment names not using DerefMut before the data is initialized, but this can be hard because Deref/DerefMut calls are inserted implicitly, I would prefer explicit functions instead (AsRef/AsMut implementations), but this would be a breaking change. Also, I added some API to get raw pointers, so maybe the function this doc comment is for can be useful. |
daedric
reviewed
Sep 23, 2024
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.
See commit messages for detailed explanations.
Message::with_sizeand<Message as From<&[u8]>>::fromcallmsg.as_mut_ptr()on amsgthat contains uninitialized bytes,as_mut_ptrdid not exist on Message, so the one of&mut [u8]was used, throughDerefMut. This created a&mut [u8]to uninitialized data.