mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-10 20:19:07 +00:00
crosvm: Fix clippy::correctness error
Fix a style problem categorized into `clippy::correctness`, which causes an error by default. BUG=chromium:908640 TEST=cargo clippy --all-features --all-targets -- -D clippy:correctness Change-Id: I85f54c9b031a1628127041e85678c88f1c72d4df Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145535 Tested-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
This commit is contained in:
parent
275c1ef45d
commit
05489a7637
1 changed files with 13 additions and 0 deletions
|
@ -68,6 +68,8 @@ pub enum Error {
|
|||
PreservingFd(i32),
|
||||
/// Program size is too large
|
||||
ProgramTooLarge,
|
||||
/// Alignment of file should be divisible by the alignment of sock_filter.
|
||||
WrongProgramAlignment,
|
||||
/// File size should be non-zero and a multiple of sock_filter
|
||||
WrongProgramSize,
|
||||
}
|
||||
|
@ -148,6 +150,10 @@ impl Display for Error {
|
|||
ProcFd(s) => write!(f, "an entry in /proc/self/fd is not an integer: {}", s),
|
||||
PreservingFd(e) => write!(f, "fork failed in minijail_preserve_fd with error {}", e),
|
||||
ProgramTooLarge => write!(f, "bpf program is too large (max 64K instructions)"),
|
||||
WrongProgramAlignment => write!(
|
||||
f,
|
||||
"the alignment of bpf file was not a multiple of that of sock_filter"
|
||||
),
|
||||
WrongProgramSize => write!(f, "bpf file was empty or not a multiple of sock_filter"),
|
||||
}
|
||||
}
|
||||
|
@ -287,6 +293,13 @@ impl Minijail {
|
|||
if count > (!0 as u16) as usize {
|
||||
return Err(Error::ProgramTooLarge);
|
||||
}
|
||||
if buffer.as_ptr() as usize % std::mem::align_of::<sock_filter>() != 0 {
|
||||
return Err(Error::WrongProgramAlignment);
|
||||
}
|
||||
|
||||
// Safe cast because we checked that the buffer address is divisible by the alignment of
|
||||
// sock_filter.
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let header = sock_fprog {
|
||||
len: count as c_ushort,
|
||||
filter: buffer.as_ptr() as *mut sock_filter,
|
||||
|
|
Loading…
Reference in a new issue