Skip to content

Commit

Permalink
Merge #1978
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bors[bot] and djkoloski committed Jan 27, 2023
2 parents 2d64e32 + 09a85e2 commit 1a838c7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
}
Expand Down

0 comments on commit 1a838c7

Please sign in to comment.