From 09a85e2e68028a78443e8d1d082ab4e11d59a5d7 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Tue, 24 Jan 2023 10:49:35 -0500 Subject: Null-check `libc::group` members before converting This mirrors the approach used for the `From<&libc::passwd> for User` impl. --- src/unistd.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/unistd.rs b/src/unistd.rs index 8cad67f4..36ae480a 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -3735,11 +3735,23 @@ impl From<&libc::group> for Group { fn from(gr: &libc::group) -> Group { unsafe { Group { - name: CStr::from_ptr(gr.gr_name).to_string_lossy().into_owned(), - passwd: CString::new(CStr::from_ptr(gr.gr_passwd).to_bytes()) - .unwrap(), + name: if gr.gr_name.is_null() { + Default::default() + } else { + CStr::from_ptr(gr.gr_name).to_string_lossy().into_owned() + }, + passwd: if gr.gr_passwd.is_null() { + Default::default() + } else { + CString::new(CStr::from_ptr(gr.gr_passwd).to_bytes()) + .unwrap() + }, gid: Gid::from_raw(gr.gr_gid), - mem: Group::members(gr.gr_mem), + mem: if gr.gr_mem.is_null() { + Default::default() + } else { + Group::members(gr.gr_mem) + }, } } } -- cgit v1.2.3