File tree Expand file tree Collapse file tree
crates/openshell-supervisor-process/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -540,6 +540,18 @@ mod tests {
540540 }
541541 }
542542
543+ if std:: fs:: read_link ( format ! ( "/proc/{child_pid}/exe" ) ) . is_err ( )
544+ || std:: fs:: read_dir ( format ! ( "/proc/{child_pid}/fd" ) ) . is_err ( )
545+ {
546+ #[ allow( unsafe_code) ]
547+ unsafe {
548+ libc:: kill ( child_pid, libc:: SIGKILL ) ;
549+ libc:: waitpid ( child_pid, std:: ptr:: null_mut ( ) , 0 ) ;
550+ }
551+ eprintln ! ( "skipping: cannot read /proc/{child_pid} (restricted /proc)" ) ;
552+ return ;
553+ }
554+
543555 let deadline = Instant :: now ( ) + Duration :: from_secs ( 2 ) ;
544556 loop {
545557 if let Ok ( link) = std:: fs:: read_link ( format ! ( "/proc/{child_pid}/exe" ) )
Original file line number Diff line number Diff line change @@ -1599,6 +1599,17 @@ mod tests {
15991599 } ) ;
16001600
16011601 let result = drop_privileges ( & policy) ;
1602+ #[ cfg( target_os = "linux" ) ]
1603+ {
1604+ if nix:: unistd:: geteuid ( ) . is_root ( ) && !capability_bounding_set_clear_available ( ) {
1605+ let msg = format ! ( "{}" , result. unwrap_err( ) ) ;
1606+ assert ! (
1607+ msg. contains( "Failed to clear child capability bounding set" ) ,
1608+ "unexpected failure: {msg}"
1609+ ) ;
1610+ return ;
1611+ }
1612+ }
16021613 assert ! ( result. is_ok( ) , "drop_privileges failed: {result:?}" ) ;
16031614 }
16041615
@@ -1913,9 +1924,10 @@ mod tests {
19131924 return ;
19141925 }
19151926
1916- let current_user = User :: from_uid ( nix:: unistd:: geteuid ( ) )
1917- . unwrap ( )
1918- . expect ( "current user entry" ) ;
1927+ let Ok ( Some ( current_user) ) = User :: from_uid ( nix:: unistd:: geteuid ( ) ) else {
1928+ eprintln ! ( "skipping: current UID has no /etc/passwd entry" ) ;
1929+ return ;
1930+ } ;
19191931 let restricted_group = Group :: from_gid ( Gid :: from_raw ( 0 ) )
19201932 . unwrap ( )
19211933 . expect ( "gid 0 group entry" ) ;
You can’t perform that action at this time.
0 commit comments