Skip to content

Commit

Permalink
Prevent future potential UB in unix wrapper for getpwuid() (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonz committed Mar 9, 2024
1 parent 358dc0e commit 4bbaf52
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ fn getpwuid(name: Name) -> Result<OsString> {
const BUF_SIZE: usize = 16_384; // size from the man page
let mut buffer = mem::MaybeUninit::<[u8; BUF_SIZE]>::uninit();
let mut passwd = mem::MaybeUninit::<PassWd>::uninit();
let mut _passwd = mem::MaybeUninit::<*mut PassWd>::uninit();

// Get PassWd `struct`.
let passwd = unsafe {
Expand All @@ -251,6 +250,7 @@ fn getpwuid(name: Name) -> Result<OsString> {
target_os = "openbsd",
))]
{
let mut _passwd = mem::MaybeUninit::<*mut PassWd>::uninit();
let ret = getpwuid_r(
geteuid(),
passwd.as_mut_ptr(),
Expand All @@ -268,6 +268,7 @@ fn getpwuid(name: Name) -> Result<OsString> {
if _passwd.is_null() {
return Err(super::err_null_record());
}
passwd.assume_init()
}

#[cfg(target_os = "illumos")]
Expand All @@ -282,9 +283,8 @@ fn getpwuid(name: Name) -> Result<OsString> {
if ret.is_null() {
return Err(Error::last_os_error());
}
passwd.assume_init()
}

passwd.assume_init()
};

// Extract names.
Expand Down

0 comments on commit 4bbaf52

Please sign in to comment.