Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unaligned read panic on macos #2311

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}