Skip to content

Commit 7aaf808

Browse files
bors[bot]wdsgyj
andauthored
Merge #1824
1824: fix bugs on android armv7, because `pw.pw_passwd.is_null()` r=rtzoeller a=ClarkGuan crash on my Android phone because `pw.pw_passwd == NULL` Co-authored-by: wdsgyj <gongbo.guan@momenta.ai>
2 parents be36bf0 + 9b232dd commit 7aaf808

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2727
- Fix `User::from_name` and `Group::from_name` panicking
2828
when given a name containing a nul.
2929
([#1815](https://github.com/nix-rust/nix/pull/1815))
30+
- Fix `User::from_uid` and `User::from_name` crash on Android platform.
31+
([#1824](https://github.com/nix-rust/nix/pull/1824))
3032

3133
### Removed
3234

src/unistd.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,12 +2984,12 @@ impl From<&libc::passwd> for User {
29842984
fn from(pw: &libc::passwd) -> User {
29852985
unsafe {
29862986
User {
2987-
name: CStr::from_ptr(pw.pw_name).to_string_lossy().into_owned(),
2988-
passwd: CString::new(CStr::from_ptr(pw.pw_passwd).to_bytes()).unwrap(),
2987+
name: if pw.pw_name.is_null() { Default::default() } else { CStr::from_ptr(pw.pw_name).to_string_lossy().into_owned() },
2988+
passwd: if pw.pw_passwd.is_null() { Default::default() } else { CString::new(CStr::from_ptr(pw.pw_passwd).to_bytes()).unwrap() },
29892989
#[cfg(not(all(target_os = "android", target_pointer_width = "32")))]
2990-
gecos: CString::new(CStr::from_ptr(pw.pw_gecos).to_bytes()).unwrap(),
2991-
dir: PathBuf::from(OsStr::from_bytes(CStr::from_ptr(pw.pw_dir).to_bytes())),
2992-
shell: PathBuf::from(OsStr::from_bytes(CStr::from_ptr(pw.pw_shell).to_bytes())),
2990+
gecos: if pw.pw_gecos.is_null() { Default::default() } else { CString::new(CStr::from_ptr(pw.pw_gecos).to_bytes()).unwrap() },
2991+
dir: if pw.pw_dir.is_null() { Default::default() } else { PathBuf::from(OsStr::from_bytes(CStr::from_ptr(pw.pw_dir).to_bytes())) },
2992+
shell: if pw.pw_shell.is_null() { Default::default() } else { PathBuf::from(OsStr::from_bytes(CStr::from_ptr(pw.pw_shell).to_bytes())) },
29932993
uid: Uid::from_raw(pw.pw_uid),
29942994
gid: Gid::from_raw(pw.pw_gid),
29952995
#[cfg(not(any(target_os = "android",

0 commit comments

Comments
 (0)