From 40a443dd749ea374d8eb9c59f927c09a74c33ef5 Mon Sep 17 00:00:00 2001 From: Nate W Date: Wed, 7 Jun 2023 13:00:12 +0200 Subject: [PATCH] Early return UID/GID if nonexistent If a UID/GID doesn't exist on the system, just print the value of it instead of hard crashing. --- src/fs/ug.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fs/ug.rs b/src/fs/ug.rs index 675c618a..fc6ab910 100644 --- a/src/fs/ug.rs +++ b/src/fs/ug.rs @@ -37,6 +37,10 @@ unsafe fn try_get_group(gid: libc::gid_t) -> Result { let errno = errno(); + if group.is_null() { + return Ok(gid.to_string()); + } + if errno.0 != 0 { return Err(errno); } @@ -54,6 +58,10 @@ unsafe fn try_get_user(uid: libc::uid_t) -> Result { let errno = errno(); + if pwd.is_null() { + return Ok(uid.to_string()); + } + if errno.0 != 0 { return Err(errno); }