From 0c6ee2dc7898068ca3519db59c1c2f59a99027c3 Mon Sep 17 00:00:00 2001 From: Marc Schoolderman Date: Mon, 8 Apr 2024 16:33:12 +0200 Subject: [PATCH 1/2] appease clippy warnings originating from rust 1.77 --- src/exec/use_pty/pipe/ring_buffer.rs | 4 ++++ src/visudo/mod.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/src/exec/use_pty/pipe/ring_buffer.rs b/src/exec/use_pty/pipe/ring_buffer.rs index f87555ecf..c66ed68b4 100644 --- a/src/exec/use_pty/pipe/ring_buffer.rs +++ b/src/exec/use_pty/pipe/ring_buffer.rs @@ -25,6 +25,8 @@ impl RingBuffer { self.len == self.storage.len() } + // rustc 1.77.1 clippy gives false diagnostics, https://github.com/rust-lang/rust-clippy/issues/12519 + #[allow(clippy::unused_io_amount)] pub(super) fn insert(&mut self, read: &mut R) -> io::Result { let inserted_len = if self.is_empty() { // Case 1.1. The buffer is empty, meaning that there are two unfilled slices in @@ -61,6 +63,8 @@ impl RingBuffer { self.len == 0 } + // rustc 1.77.1 clippy gives false diagnostics, https://github.com/rust-lang/rust-clippy/issues/12519 + #[allow(clippy::unused_io_amount)] pub(super) fn remove(&mut self, write: &mut W) -> io::Result { let removed_len = if self.is_full() { // Case 2.1. The buffer is full, meaning that there are two filled slices in `storage`: diff --git a/src/visudo/mod.rs b/src/visudo/mod.rs index ebe5169c6..b9dd1f992 100644 --- a/src/visudo/mod.rs +++ b/src/visudo/mod.rs @@ -172,6 +172,7 @@ fn run(file_arg: Option<&str>, perms: bool, owner: bool) -> io::Result<()> { .read(true) .write(true) .create(true) + .truncate(true) .open(&tmp_path)?; tmp_file.set_permissions(Permissions::from_mode(0o700))?; From 266d07ca42ba079b80023bc26649c8260516519b Mon Sep 17 00:00:00 2001 From: Marc Schoolderman Date: Mon, 8 Apr 2024 16:35:49 +0200 Subject: [PATCH 2/2] appease clippy --tests (indeed the zeroed_sigaction was in the wrong spot) --- src/su/cli.rs | 1 + src/sudo/cli/mod.rs | 1 + src/system/mod.rs | 14 +++++++------- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/su/cli.rs b/src/su/cli.rs index fed7238bf..9587d5d54 100644 --- a/src/su/cli.rs +++ b/src/su/cli.rs @@ -22,6 +22,7 @@ impl SuAction { } #[cfg(test)] + #[allow(clippy::result_large_err)] pub fn try_into_run(self) -> Result { if let Self::Run(v) = self { Ok(v) diff --git a/src/sudo/cli/mod.rs b/src/sudo/cli/mod.rs index 33081d34f..49a00f257 100644 --- a/src/sudo/cli/mod.rs +++ b/src/sudo/cli/mod.rs @@ -80,6 +80,7 @@ impl SudoAction { } #[cfg(test)] + #[allow(clippy::result_large_err)] pub fn try_into_run(self) -> Result { if let Self::Run(v) = self { Ok(v) diff --git a/src/system/mod.rs b/src/system/mod.rs index f90588ce4..5698beb39 100644 --- a/src/system/mod.rs +++ b/src/system/mod.rs @@ -672,6 +672,13 @@ pub fn escape_os_str_lossy(s: &std::ffi::OsStr) -> String { s.to_string_lossy().escape_default().collect() } +pub fn make_zeroed_sigaction() -> libc::sigaction { + // SAFETY: since sigaction is a C struct, all-zeroes is a valid representation + // We cannot use a "literal struct" initialization method since the exact representation + // of libc::sigaction is not fixed, see e.g. https://github.com/memorysafety/sudo-rs/issues/829 + unsafe { std::mem::zeroed() } +} + #[cfg(test)] mod tests { use std::{ @@ -894,10 +901,3 @@ mod tests { assert_eq!(status.exit_status(), Some(0)); } } - -pub fn make_zeroed_sigaction() -> libc::sigaction { - // SAFETY: since sigaction is a C struct, all-zeroes is a valid representation - // We cannot use a "literal struct" initialization method since the exact representation - // of libc::sigaction is not fixed, see e.g. https://github.com/memorysafety/sudo-rs/issues/829 - unsafe { std::mem::zeroed() } -}