Skip to content

Commit 1a838c7

Browse files
bors[bot]djkoloski
andauthored
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 <[email protected]>
2 parents 2d64e32 + 09a85e2 commit 1a838c7

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/unistd.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,11 +3750,23 @@ impl From<&libc::group> for Group {
37503750
fn from(gr: &libc::group) -> Group {
37513751
unsafe {
37523752
Group {
3753-
name: CStr::from_ptr(gr.gr_name).to_string_lossy().into_owned(),
3754-
passwd: CString::new(CStr::from_ptr(gr.gr_passwd).to_bytes())
3755-
.unwrap(),
3753+
name: if gr.gr_name.is_null() {
3754+
Default::default()
3755+
} else {
3756+
CStr::from_ptr(gr.gr_name).to_string_lossy().into_owned()
3757+
},
3758+
passwd: if gr.gr_passwd.is_null() {
3759+
Default::default()
3760+
} else {
3761+
CString::new(CStr::from_ptr(gr.gr_passwd).to_bytes())
3762+
.unwrap()
3763+
},
37563764
gid: Gid::from_raw(gr.gr_gid),
3757-
mem: Group::members(gr.gr_mem),
3765+
mem: if gr.gr_mem.is_null() {
3766+
Default::default()
3767+
} else {
3768+
Group::members(gr.gr_mem)
3769+
},
37583770
}
37593771
}
37603772
}

0 commit comments

Comments
 (0)