Skip to content

Commit 4315c10

Browse files
committed
fix: unaligned read panic on macos
1 parent 64e2de0 commit 4315c10

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

changelog/2311.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed `::unistd::Group::members` crash on misaligned read by read_unaligned use

src/unistd.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3569,13 +3569,41 @@ impl Group {
35693569
///
35703570
/// # Examples
35713571
///
3572+
// Disable this test on all OS except BSD as wheel group may not exist.
3573+
#[cfg_attr(not(bsd), doc = " ```no_run")]
3574+
#[cfg_attr(bsd, doc = " ```")]
3575+
/// use nix::unistd::Group;
3576+
/// // Returns an Result<Option<Group>>, thus the double unwrap.
3577+
/// let group = Group::from_name("wheel").unwrap().unwrap();
3578+
/// assert!(group.name == "wheel");
3579+
/// let group_id = group.gid;
3580+
/// let group = Group::from_gid(group_id).unwrap().unwrap();
3581+
/// assert_eq!(group.gid, group_id);
3582+
/// assert_eq!(group.name, "wheel");
3583+
/// ```
3584+
// Disable this test on all OS except Apple as everyone group may not exist.
3585+
#[cfg_attr(not(apple_targets), doc = " ```no_run")]
3586+
#[cfg_attr(apple_targets, doc = " ```")]
3587+
/// use nix::unistd::Group;
3588+
/// // Returns an Result<Option<Group>>, thus the double unwrap.
3589+
/// let group = Group::from_name("everyone").unwrap().unwrap();
3590+
/// assert!(group.name == "everyone");
3591+
/// let group_id = group.gid;
3592+
/// let group = Group::from_gid(group_id).unwrap().unwrap();
3593+
/// assert_eq!(group.gid, group_id);
3594+
/// assert_eq!(group.name, "everyone");
3595+
/// ```
35723596
// Disable this test on all OS except Linux as root group may not exist.
35733597
#[cfg_attr(not(target_os = "linux"), doc = " ```no_run")]
35743598
#[cfg_attr(target_os = "linux", doc = " ```")]
35753599
/// use nix::unistd::Group;
35763600
/// // Returns an Result<Option<Group>>, thus the double unwrap.
3577-
/// let res = Group::from_name("root").unwrap().unwrap();
3578-
/// assert!(res.name == "root");
3601+
/// let group = Group::from_name("root").unwrap().unwrap();
3602+
/// assert!(group.name == "root");
3603+
/// let group_id = group.gid;
3604+
/// let group = Group::from_gid(group_id).unwrap().unwrap();
3605+
/// assert_eq!(group.gid, group_id);
3606+
/// assert_eq!(group.name, "root");
35793607
/// ```
35803608
pub fn from_name(name: &str) -> Result<Option<Self>> {
35813609
let name = match CString::new(name) {

0 commit comments

Comments
 (0)