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/).
27
27
- Fix ` User::from_name ` and ` Group::from_name ` panicking
28
28
when given a name containing a nul.
29
29
([ #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 ) )
30
32
31
33
### Removed
32
34
Original file line number Diff line number Diff line change @@ -2984,12 +2984,12 @@ impl From<&libc::passwd> for User {
2984
2984
fn from( pw: & libc:: passwd) -> User {
2985
2985
unsafe {
2986
2986
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( ) } ,
2989
2989
#[ 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( ) ) ) } ,
2993
2993
uid: Uid :: from_raw( pw. pw_uid) ,
2994
2994
gid: Gid :: from_raw( pw. pw_gid) ,
2995
2995
#[ cfg( not( any( target_os = "android" ,
You can’t perform that action at this time.
0 commit comments