From c8977a78a417bbb26afb54982c2cc20ef298c3e6 Mon Sep 17 00:00:00 2001 From: Alex Lyon Date: Thu, 18 Feb 2021 23:38:57 -0800 Subject: [PATCH] uucore: fix potential use-after-free in utmpx iterator (#1737) --- src/uucore/src/lib/features/utmpx.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index ab3de65fa..31cd3b72c 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -242,9 +242,10 @@ impl UtmpxIter { /// /// If not set, default record file will be used(file path depends on the target OS) pub fn read_from(self, f: &str) -> Self { - // FixME: discuss and revise a rewrite which is correct and satisfies clippy/rustc - #[allow(clippy::temporary_cstring_as_ptr)] - let res = unsafe { utmpxname(CString::new(f).unwrap().as_ptr()) }; + let res = unsafe { + let cstr = CString::new(f).unwrap(); + utmpxname(cstr.as_ptr()) + }; if res != 0 { println!("Warning: {}", IOError::last_os_error()); }