uucore: fix potential use-after-free in utmpx iterator (#1737)

This commit is contained in:
Alex Lyon 2021-02-18 23:38:57 -08:00 committed by GitHub
parent 15eaaa9473
commit c8977a78a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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());
}