@@ -183,6 +183,8 @@ static int usage() {
183
183
fprintf (stderr, " exit call exit(1)\n " );
184
184
fprintf (stderr, " \n " );
185
185
fprintf (stderr, " fortify fail a _FORTIFY_SOURCE check\n " );
186
+ fprintf (stderr, " fdsan_file close a file descriptor that's owned by a FILE*\n " );
187
+ fprintf (stderr, " fdsan_dir close a file descriptor that's owned by a DIR*\n " );
186
188
fprintf (stderr, " seccomp fail a seccomp check\n " );
187
189
#if defined(__arm__)
188
190
fprintf (stderr, " kuser_helper_version call kuser_helper_version\n " );
@@ -236,39 +238,45 @@ noinline int do_action(const char* arg) {
236
238
237
239
// Actions.
238
240
if (!strcasecmp (arg, " SIGSEGV-non-null" )) {
239
- sigsegv_non_null ();
241
+ sigsegv_non_null ();
240
242
} else if (!strcasecmp (arg, " smash-stack" )) {
241
- volatile int len = 128 ;
242
- return smash_stack (&len);
243
+ volatile int len = 128 ;
244
+ return smash_stack (&len);
243
245
} else if (!strcasecmp (arg, " stack-overflow" )) {
244
- overflow_stack (nullptr );
246
+ overflow_stack (nullptr );
245
247
} else if (!strcasecmp (arg, " nostack" )) {
246
- crashnostack ();
248
+ crashnostack ();
247
249
} else if (!strcasecmp (arg, " exit" )) {
248
- exit (1 );
250
+ exit (1 );
249
251
} else if (!strcasecmp (arg, " call-null" )) {
250
252
return crash_null ();
251
253
} else if (!strcasecmp (arg, " crash" ) || !strcmp (arg, " SIGSEGV" )) {
252
- return crash (42 );
254
+ return crash (42 );
253
255
} else if (!strcasecmp (arg, " abort" )) {
254
- maybe_abort ();
256
+ maybe_abort ();
255
257
} else if (!strcasecmp (arg, " assert" )) {
256
- __assert (" some_file.c" , 123 , " false" );
258
+ __assert (" some_file.c" , 123 , " false" );
257
259
} else if (!strcasecmp (arg, " assert2" )) {
258
- __assert2 (" some_file.c" , 123 , " some_function" , " false" );
260
+ __assert2 (" some_file.c" , 123 , " some_function" , " false" );
259
261
} else if (!strcasecmp (arg, " fortify" )) {
260
- char buf[10 ];
261
- __read_chk (-1 , buf, 32 , 10 );
262
- while (true ) pause ();
262
+ char buf[10 ];
263
+ __read_chk (-1 , buf, 32 , 10 );
264
+ while (true ) pause ();
265
+ } else if (!strcasecmp (arg, " fdsan_file" )) {
266
+ FILE* f = fopen (" /dev/null" , " r" );
267
+ close (fileno (f));
268
+ } else if (!strcasecmp (arg, " fdsan_dir" )) {
269
+ DIR* d = opendir (" /dev/" );
270
+ close (dirfd (d));
263
271
} else if (!strcasecmp (arg, " LOG(FATAL)" )) {
264
- LOG (FATAL) << " hello " << 123 ;
272
+ LOG (FATAL) << " hello " << 123 ;
265
273
} else if (!strcasecmp (arg, " LOG_ALWAYS_FATAL" )) {
266
- LOG_ALWAYS_FATAL (" hello %s" , " world" );
274
+ LOG_ALWAYS_FATAL (" hello %s" , " world" );
267
275
} else if (!strcasecmp (arg, " LOG_ALWAYS_FATAL_IF" )) {
268
- LOG_ALWAYS_FATAL_IF (true , " hello %s" , " world" );
276
+ LOG_ALWAYS_FATAL_IF (true , " hello %s" , " world" );
269
277
} else if (!strcasecmp (arg, " SIGFPE" )) {
270
- raise (SIGFPE);
271
- return EXIT_SUCCESS;
278
+ raise (SIGFPE);
279
+ return EXIT_SUCCESS;
272
280
} else if (!strcasecmp (arg, " SIGILL" )) {
273
281
#if defined(__aarch64__)
274
282
__asm__ volatile (" .word 0\n " );
@@ -280,28 +288,28 @@ noinline int do_action(const char* arg) {
280
288
#error
281
289
#endif
282
290
} else if (!strcasecmp (arg, " SIGTRAP" )) {
283
- raise (SIGTRAP);
284
- return EXIT_SUCCESS;
291
+ raise (SIGTRAP);
292
+ return EXIT_SUCCESS;
285
293
} else if (!strcasecmp (arg, " fprintf-NULL" )) {
286
- fprintf_null ();
294
+ fprintf_null ();
287
295
} else if (!strcasecmp (arg, " readdir-NULL" )) {
288
- readdir_null ();
296
+ readdir_null ();
289
297
} else if (!strcasecmp (arg, " strlen-NULL" )) {
290
- return strlen_null ();
298
+ return strlen_null ();
291
299
} else if (!strcasecmp (arg, " pthread_join-NULL" )) {
292
- return pthread_join (0 , nullptr );
300
+ return pthread_join (0 , nullptr );
293
301
} else if (!strcasecmp (arg, " heap-usage" )) {
294
- abuse_heap ();
302
+ abuse_heap ();
295
303
} else if (!strcasecmp (arg, " leak" )) {
296
- leak ();
304
+ leak ();
297
305
} else if (!strcasecmp (arg, " SIGSEGV-unmapped" )) {
298
- char * map = reinterpret_cast <char *>(mmap ( nullptr , sizeof ( int ), PROT_READ | PROT_WRITE,
299
- MAP_SHARED | MAP_ANONYMOUS, -1 , 0 ));
300
- munmap (map, sizeof (int ));
301
- map[0 ] = ' 8' ;
306
+ char * map = reinterpret_cast <char *>(
307
+ mmap ( nullptr , sizeof ( int ), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1 , 0 ));
308
+ munmap (map, sizeof (int ));
309
+ map[0 ] = ' 8' ;
302
310
} else if (!strcasecmp (arg, " seccomp" )) {
303
- set_system_seccomp_filter ();
304
- syscall (99999 );
311
+ set_system_seccomp_filter ();
312
+ syscall (99999 );
305
313
#if defined(__arm__)
306
314
} else if (!strcasecmp (arg, " kuser_helper_version" )) {
307
315
return __kuser_helper_version;
0 commit comments