@@ -10,13 +10,12 @@ use libc::{c_int, pid_t};
1010) ) ) ]
1111use libc:: { gid_t, uid_t} ;
1212
13- use crate :: io:: { self , Error , ErrorKind } ;
1413use crate :: num:: NonZero ;
1514use crate :: sys:: cvt;
1615#[ cfg( target_os = "linux" ) ]
1716use crate :: sys:: pal:: unix:: linux:: pidfd:: PidFd ;
1817use crate :: sys:: process:: process_common:: * ;
19- use crate :: { fmt, mem, sys} ;
18+ use crate :: { fmt, io , mem, sys} ;
2019
2120cfg_if:: cfg_if! {
2221 // This workaround is only needed for QNX 7.0 and 7.1. The bug should have been fixed in 8.0
@@ -60,12 +59,7 @@ impl Command {
6059
6160 let envp = self . capture_env ( ) ;
6261
63- if self . saw_nul ( ) {
64- return Err ( io:: const_io_error!(
65- ErrorKind :: InvalidInput ,
66- "nul byte found in provided data" ,
67- ) ) ;
68- }
62+ self . validate_input ( ) ?;
6963
7064 let ( ours, theirs) = self . setup_io ( default, needs_stdin) ?;
7165
@@ -146,7 +140,7 @@ impl Command {
146140 ) ;
147141 let errno = i32:: from_be_bytes ( errno. try_into ( ) . unwrap ( ) ) ;
148142 assert ! ( p. wait( ) . is_ok( ) , "wait() should either return Ok or panic" ) ;
149- return Err ( Error :: from_raw_os_error ( errno) ) ;
143+ return Err ( io :: Error :: from_raw_os_error ( errno) ) ;
150144 }
151145 Err ( ref e) if e. is_interrupted ( ) => { }
152146 Err ( e) => {
@@ -175,8 +169,8 @@ impl Command {
175169 // allowed to exist in dead code), but it sounds bad, so we go out of our
176170 // way to avoid that all-together.
177171 #[ cfg( any( target_os = "tvos" , target_os = "watchos" ) ) ]
178- const ERR_APPLE_TV_WATCH_NO_FORK_EXEC : Error = io:: const_io_error!(
179- ErrorKind :: Unsupported ,
172+ const ERR_APPLE_TV_WATCH_NO_FORK_EXEC : io :: Error = io:: const_io_error!(
173+ io :: ErrorKind :: Unsupported ,
180174 "`fork`+`exec`-based process spawning is not supported on this target" ,
181175 ) ;
182176
@@ -219,7 +213,7 @@ impl Command {
219213 thread:: sleep ( delay) ;
220214 } else {
221215 return Err ( io:: const_io_error!(
222- ErrorKind :: WouldBlock ,
216+ io :: ErrorKind :: WouldBlock ,
223217 "forking returned EBADF too often" ,
224218 ) ) ;
225219 }
@@ -234,8 +228,8 @@ impl Command {
234228 pub fn exec ( & mut self , default : Stdio ) -> io:: Error {
235229 let envp = self . capture_env ( ) ;
236230
237- if self . saw_nul ( ) {
238- return io :: const_io_error! ( ErrorKind :: InvalidInput , "nul byte found in provided data" , ) ;
231+ if let Err ( err ) = self . validate_input ( ) {
232+ return err ;
239233 }
240234
241235 match self . setup_io ( default, true ) {
@@ -561,7 +555,7 @@ impl Command {
561555 thread:: sleep ( delay) ;
562556 } else {
563557 return Err ( io:: const_io_error!(
564- ErrorKind :: WouldBlock ,
558+ io :: ErrorKind :: WouldBlock ,
565559 "posix_spawnp returned EBADF too often" ,
566560 ) ) ;
567561 }
@@ -729,7 +723,7 @@ impl Command {
729723 // But we cannot obtain its pid even though pidfd_getpid support was verified earlier.
730724 // This might happen if libc can't open procfs because the file descriptor limit has been reached.
731725 libc:: close ( pidfd) ;
732- return Err ( Error :: new (
726+ return Err ( io :: Error :: new (
733727 e. kind ( ) ,
734728 "pidfd_spawnp succeeded but the child's PID could not be obtained" ,
735729 ) ) ;
@@ -1190,7 +1184,6 @@ impl ExitStatusError {
11901184mod linux_child_ext {
11911185
11921186 use crate :: os:: linux:: process as os;
1193- use crate :: sys:: pal:: unix:: ErrorKind ;
11941187 use crate :: sys:: pal:: unix:: linux:: pidfd as imp;
11951188 use crate :: sys_common:: FromInner ;
11961189 use crate :: { io, mem} ;
@@ -1203,7 +1196,9 @@ mod linux_child_ext {
12031196 . as_ref ( )
12041197 // SAFETY: The os type is a transparent wrapper, therefore we can transmute references
12051198 . map ( |fd| unsafe { mem:: transmute :: < & imp:: PidFd , & os:: PidFd > ( fd) } )
1206- . ok_or_else ( || io:: Error :: new ( ErrorKind :: Uncategorized , "No pidfd was created." ) )
1199+ . ok_or_else ( || {
1200+ io:: Error :: new ( io:: ErrorKind :: Uncategorized , "No pidfd was created." )
1201+ } )
12071202 }
12081203
12091204 fn into_pidfd ( mut self ) -> Result < os:: PidFd , Self > {
0 commit comments