Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Commit

Permalink
Don't reference unaligned packed field
Browse files Browse the repository at this point in the history
This will be an error some day.

warning: reference to packed field is unaligned
   --> src/certs/sev/cert/mod.rs:176:47
    |
176 |             1 => PublicKey::try_from(unsafe { &value.v1.body.data.key }),
    |                                               ^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unaligned_references)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #82523 <rust-lang/rust#82523>
    = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

Also bump the minimum stable compiler. The addr_of! macro was introduced in
1.51.0.

Signed-off-by: Connor Kuehl <[email protected]>
  • Loading branch information
Connor Kuehl authored and npmccallum committed Aug 9, 2021
1 parent 695bf2d commit cd6afd9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- nightly
- beta
- stable
- 1.42.0
- 1.51.0
profile:
- name: debug
- name: release
Expand Down
4 changes: 3 additions & 1 deletion src/certs/sev/cert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ impl TryFrom<&Certificate> for PublicKey<Usage> {

fn try_from(value: &Certificate) -> Result<Self> {
match value.version() {
1 => PublicKey::try_from(unsafe { &value.v1.body.data.key }),
1 => PublicKey::try_from(unsafe {
&std::ptr::addr_of!(value.v1.body.data.key).read_unaligned()
}),
_ => Err(ErrorKind::InvalidInput.into()),
}
}
Expand Down

0 comments on commit cd6afd9

Please sign in to comment.