bug: Fix getpwuid segfault (#440)
Fixes a rare segfault if a uid does not have a passwd entry. The unsafe block at https://github.com/ClementTsang/bottom/blob/master/src/app/data_harvester/processes.rs#L137 can return a null pointer as specified at https://www.gnu.org/software/libc/manual/html_node/Lookup-User.html.
This commit is contained in:
parent
b8fb78a769
commit
c79956843e
|
@ -134,7 +134,13 @@ impl UserTable {
|
|||
if let Some(user) = self.uid_user_mapping.get(&uid) {
|
||||
Ok(user.clone())
|
||||
} else {
|
||||
// SAFETY: getpwuid returns a null pointer if no passwd entry is found for the uid
|
||||
let passwd = unsafe { libc::getpwuid(uid) };
|
||||
|
||||
if passwd.is_null() {
|
||||
return Err(error::BottomError::QueryError("Missing passwd".into()));
|
||||
}
|
||||
|
||||
let username = unsafe { std::ffi::CStr::from_ptr((*passwd).pw_name) }
|
||||
.to_str()?
|
||||
.to_string();
|
||||
|
|
Loading…
Reference in New Issue