Skip to content

Commit

Permalink
refactor: update nix (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonkey authored Feb 17, 2024
1 parent f34d00d commit 197f55b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ jobs:
- name: before_cache_script
run: rm -rf $CARGO_HOME/registry/index

macos-aarch64:
runs-on: macos-14
env:
TARGET: aarch64-apple-darwin
steps:
- name: checkout
uses: actions/checkout@v4

- name: setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: '${{ env.MSRV }}'
components: clippy

- name: build
uses: ./.github/actions/build
with:
TARGET: "${{ env.TARGET }}"

- name: test
uses: ./.github/actions/test
with:
TARGET: "${{ env.TARGET }}"

- name: before_cache_script
run: rm -rf $CARGO_HOME/registry/index

# Use cross for QEMU-based testing
# cross needs to execute Docker, GitHub Action already has it installed
Expand Down
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` using read_unaligned to avoid crash on misaligned pointers
7 changes: 3 additions & 4 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3476,18 +3476,17 @@ impl Group {
let mut ret = Vec::new();

for i in 0.. {
let u = unsafe { mem.offset(i) };
if unsafe { (*u).is_null() } {
let u = unsafe { mem.offset(i).read_unaligned() };
if u.is_null() {
break;
} else {
let s = unsafe {CStr::from_ptr(*u).to_string_lossy().into_owned()};
let s = unsafe {CStr::from_ptr(u).to_string_lossy().into_owned()};
ret.push(s);
}
}

ret
}

/// # Safety
///
/// If `f` writes to its `*mut *mut libc::group` parameter, then it must
Expand Down
11 changes: 11 additions & 0 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,3 +1372,14 @@ fn test_eaccess_file_exists() {
eaccess(&path, AccessFlags::R_OK | AccessFlags::W_OK)
.expect("assertion failed");
}

#[test]
#[cfg(bsd)]
fn test_group_from() {
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");
}

0 comments on commit 197f55b

Please sign in to comment.