Skip to content

Commit

Permalink
fix: unaligned read panic on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
anonkey committed Feb 7, 2024
1 parent 64e2de0 commit 4315c10
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/2311.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed `::unistd::Group::members` crash on misaligned read by read_unaligned use
32 changes: 30 additions & 2 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3569,13 +3569,41 @@ impl Group {
///
/// # Examples
///
// Disable this test on all OS except BSD as wheel group may not exist.
#[cfg_attr(not(bsd), doc = " ```no_run")]
#[cfg_attr(bsd, doc = " ```")]
/// use nix::unistd::Group;
/// // Returns an Result<Option<Group>>, thus the double unwrap.
/// let group = Group::from_name("wheel").unwrap().unwrap();
/// assert!(group.name == "wheel");
/// let group_id = group.gid;
/// let group = Group::from_gid(group_id).unwrap().unwrap();
/// assert_eq!(group.gid, group_id);
/// assert_eq!(group.name, "wheel");
/// ```
// Disable this test on all OS except Apple as everyone group may not exist.
#[cfg_attr(not(apple_targets), doc = " ```no_run")]
#[cfg_attr(apple_targets, doc = " ```")]
/// use nix::unistd::Group;
/// // Returns an Result<Option<Group>>, thus the double unwrap.
/// let group = Group::from_name("everyone").unwrap().unwrap();
/// assert!(group.name == "everyone");
/// let group_id = group.gid;
/// let group = Group::from_gid(group_id).unwrap().unwrap();
/// assert_eq!(group.gid, group_id);
/// assert_eq!(group.name, "everyone");
/// ```
// Disable this test on all OS except Linux as root group may not exist.
#[cfg_attr(not(target_os = "linux"), doc = " ```no_run")]
#[cfg_attr(target_os = "linux", doc = " ```")]
/// use nix::unistd::Group;
/// // Returns an Result<Option<Group>>, thus the double unwrap.
/// let res = Group::from_name("root").unwrap().unwrap();
/// assert!(res.name == "root");
/// let group = Group::from_name("root").unwrap().unwrap();
/// assert!(group.name == "root");
/// let group_id = group.gid;
/// let group = Group::from_gid(group_id).unwrap().unwrap();
/// assert_eq!(group.gid, group_id);
/// assert_eq!(group.name, "root");
/// ```
pub fn from_name(name: &str) -> Result<Option<Self>> {
let name = match CString::new(name) {
Expand Down

0 comments on commit 4315c10

Please sign in to comment.