File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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" ,
You can’t perform that action at this time.
0 commit comments