11use crate :: fmt;
2- use crate :: io:: { self , Error , ErrorKind } ;
2+ use crate :: io:: { self , Error } ;
33use crate :: mem;
44use crate :: num:: NonZero ;
55use crate :: sys;
@@ -64,12 +64,7 @@ impl Command {
6464
6565 let envp = self . capture_env ( ) ;
6666
67- if self . saw_nul ( ) {
68- return Err ( io:: const_io_error!(
69- ErrorKind :: InvalidInput ,
70- "nul byte found in provided data" ,
71- ) ) ;
72- }
67+ self . validate_input ( ) ?;
7368
7469 let ( ours, theirs) = self . setup_io ( default, needs_stdin) ?;
7570
@@ -180,7 +175,7 @@ impl Command {
180175 // way to avoid that all-together.
181176 #[ cfg( any( target_os = "tvos" , target_os = "watchos" ) ) ]
182177 const ERR_APPLE_TV_WATCH_NO_FORK_EXEC : Error = io:: const_io_error!(
183- ErrorKind :: Unsupported ,
178+ io :: ErrorKind :: Unsupported ,
184179 "`fork`+`exec`-based process spawning is not supported on this target" ,
185180 ) ;
186181
@@ -221,7 +216,7 @@ impl Command {
221216 thread:: sleep ( delay) ;
222217 } else {
223218 return Err ( io:: const_io_error!(
224- ErrorKind :: WouldBlock ,
219+ io :: ErrorKind :: WouldBlock ,
225220 "forking returned EBADF too often" ,
226221 ) ) ;
227222 }
@@ -236,8 +231,8 @@ impl Command {
236231 pub fn exec ( & mut self , default : Stdio ) -> io:: Error {
237232 let envp = self . capture_env ( ) ;
238233
239- if self . saw_nul ( ) {
240- return io :: const_io_error! ( ErrorKind :: InvalidInput , "nul byte found in provided data" , ) ;
234+ if let Err ( err ) = self . validate_input ( ) {
235+ return err ;
241236 }
242237
243238 match self . setup_io ( default, true ) {
@@ -497,7 +492,7 @@ impl Command {
497492 thread:: sleep ( delay) ;
498493 } else {
499494 return Err ( io:: const_io_error!(
500- ErrorKind :: WouldBlock ,
495+ io :: ErrorKind :: WouldBlock ,
501496 "posix_spawnp returned EBADF too often" ,
502497 ) ) ;
503498 }
@@ -1084,7 +1079,6 @@ mod linux_child_ext {
10841079 use crate :: mem;
10851080 use crate :: os:: linux:: process as os;
10861081 use crate :: sys:: pal:: unix:: linux:: pidfd as imp;
1087- use crate :: sys:: pal:: unix:: ErrorKind ;
10881082 use crate :: sys_common:: FromInner ;
10891083
10901084 #[ unstable( feature = "linux_pidfd" , issue = "82971" ) ]
@@ -1095,7 +1089,9 @@ mod linux_child_ext {
10951089 . as_ref ( )
10961090 // SAFETY: The os type is a transparent wrapper, therefore we can transmute references
10971091 . map ( |fd| unsafe { mem:: transmute :: < & imp:: PidFd , & os:: PidFd > ( fd) } )
1098- . ok_or_else ( || io:: Error :: new ( ErrorKind :: Uncategorized , "No pidfd was created." ) )
1092+ . ok_or_else ( || {
1093+ io:: Error :: new ( io:: ErrorKind :: Uncategorized , "No pidfd was created." )
1094+ } )
10991095 }
11001096
11011097 fn into_pidfd ( mut self ) -> Result < os:: PidFd , Self > {
0 commit comments