diff options
author | Zeb Piasecki <zeb@zebulon.dev> | 2021-03-23 19:37:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-23 19:37:28 -0400 |
commit | c79956843e88154334303b607bea64601a6b5059 (patch) | |
tree | 2568856dc78bbe5dec0119da7bc0241151aa1c53 /src/app | |
parent | b8fb78a769317be88f8a3cebbf762c58ea249d57 (diff) |
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.
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/data_harvester/processes.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs index 56bf09d4..4d7beda0 100644 --- a/src/app/data_harvester/processes.rs +++ b/src/app/data_harvester/processes.rs @@ -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(); |