1
1
extern crate tempdir;
2
2
3
+ use nix:: fcntl;
3
4
use nix:: unistd:: * ;
4
5
use nix:: unistd:: ForkResult :: * ;
5
6
use nix:: sys:: wait:: * ;
@@ -190,7 +191,7 @@ fn test_initgroups() {
190
191
}
191
192
192
193
macro_rules! execve_test_factory(
193
- ( $test_name: ident, $syscall: ident, $exe: expr) => (
194
+ ( $test_name: ident, $syscall: ident, $exe: expr $ ( , $pathname : expr , $flags : expr ) * ) => (
194
195
#[ test]
195
196
fn $test_name( ) {
196
197
#[ allow( unused_variables) ]
@@ -211,12 +212,14 @@ macro_rules! execve_test_factory(
211
212
// exec!
212
213
$syscall(
213
214
$exe,
215
+ $( & CString :: new( $pathname) . unwrap( ) , ) *
214
216
& [ CString :: new( b"" . as_ref( ) ) . unwrap( ) ,
215
217
CString :: new( b"-c" . as_ref( ) ) . unwrap( ) ,
216
218
CString :: new( b"echo nix!!! && echo foo=$foo && echo baz=$baz"
217
219
. as_ref( ) ) . unwrap( ) ] ,
218
220
& [ CString :: new( b"foo=bar" . as_ref( ) ) . unwrap( ) ,
219
- CString :: new( b"baz=quux" . as_ref( ) ) . unwrap( ) ] ) . unwrap( ) ;
221
+ CString :: new( b"baz=quux" . as_ref( ) ) . unwrap( ) ]
222
+ $( , $flags) * ) . unwrap( ) ;
220
223
} ,
221
224
Parent { child } => {
222
225
// Wait for the child to exit.
@@ -239,16 +242,31 @@ cfg_if!{
239
242
if #[ cfg( target_os = "android" ) ] {
240
243
execve_test_factory!( test_execve, execve, & CString :: new( "/system/bin/sh" ) . unwrap( ) ) ;
241
244
execve_test_factory!( test_fexecve, fexecve, File :: open( "/system/bin/sh" ) . unwrap( ) . into_raw_fd( ) ) ;
245
+ execve_test_factory!( test_execveat_empty, execveat, File :: open( "/system/bin/sh" ) . unwrap( ) . into_raw_fd( ) ,
246
+ "" , fcntl:: AT_EMPTY_PATH ) ;
247
+ execve_test_factory!( test_execveat_relative, execveat, File :: open( "/system/bin/" ) . unwrap( ) . into_raw_fd( ) ,
248
+ "./sh" , fcntl:: AtFlags :: empty( ) ) ;
249
+ execve_test_factory!( test_execveat_absolute, execveat, File :: open( "/" ) . unwrap( ) . into_raw_fd( ) ,
250
+ "/system/bin/sh" , fcntl:: AtFlags :: empty( ) ) ;
251
+ } else if #[ cfg( target_os = "linux" ) ] {
252
+ execve_test_factory!( test_execve, execve, & CString :: new( "/bin/sh" ) . unwrap( ) ) ;
253
+ execve_test_factory!( test_fexecve, fexecve, File :: open( "/bin/sh" ) . unwrap( ) . into_raw_fd( ) ) ;
254
+ execve_test_factory!( test_execveat_empty, execveat, File :: open( "/bin/sh" ) . unwrap( ) . into_raw_fd( ) ,
255
+ "" , fcntl:: AT_EMPTY_PATH ) ;
256
+ execve_test_factory!( test_execveat_relative, execveat, File :: open( "/bin/" ) . unwrap( ) . into_raw_fd( ) ,
257
+ "./sh" , fcntl:: AtFlags :: empty( ) ) ;
258
+ execve_test_factory!( test_execveat_absolute, execveat, File :: open( "/" ) . unwrap( ) . into_raw_fd( ) ,
259
+ "/bin/sh" , fcntl:: AtFlags :: empty( ) ) ;
242
260
} else if #[ cfg( any( target_os = "dragonfly" ,
243
261
target_os = "freebsd" ,
244
262
target_os = "netbsd" ,
245
- target_os = "openbsd" ,
246
- target_os = "linux" , ) ) ] {
263
+ target_os = "openbsd" , ) ) ] {
264
+ // No execveat() on BSD.
247
265
execve_test_factory!( test_execve, execve, & CString :: new( "/bin/sh" ) . unwrap( ) ) ;
248
266
execve_test_factory!( test_fexecve, fexecve, File :: open( "/bin/sh" ) . unwrap( ) . into_raw_fd( ) ) ;
249
267
} else if #[ cfg( any( target_os = "ios" , target_os = "macos" , ) ) ] {
250
268
execve_test_factory!( test_execve, execve, & CString :: new( "/bin/sh" ) . unwrap( ) ) ;
251
- // No fexecve() on macos/ios.
269
+ // No fexecve() and execveat() on macos/ios.
252
270
}
253
271
}
254
272
0 commit comments