diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-01-27 21:57:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-27 21:57:37 +0000 |
commit | 1a838c7e54e6b908cc96db1c4a89dc87e8958f72 (patch) | |
tree | 64932a50d14f3b4c5074fee5100fd253031a6555 /src | |
parent | 2d64e3250649dff1640717f275a1af89dfd7bfd3 (diff) | |
parent | 09a85e2e68028a78443e8d1d082ab4e11d59a5d7 (diff) | |
download | nix-1a838c7e54e6b908cc96db1c4a89dc87e8958f72.zip |
Merge #1978
1978: Null-check `libc::group` members before converting r=rtzoeller a=djkoloski
This mirrors the approach used for the `From<&libc::passwd> for User` impl.
Co-authored-by: David Koloski <djkoloski@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/unistd.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index 89edcbef..fc3c405d 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -3750,11 +3750,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) + }, } } } |