github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/android/jni/sandbox_test.c (about)

     1  #define GOOS_linux 1
     2  #define SYZ_SANDBOX_ANDROID_UNTRUSTED_APP 1
     3  #define SYZ_USE_TMP_DIR 1
     4  #define fail(...)   do { dprintf(2, __VA_ARGS__); dprintf(2, "\n"); perror("errno"); exit(1); } while(0)
     5  #define error(...)  do { dprintf(2, __VA_ARGS__); } while(0)
     6  #define debug(...)  do { dprintf(2, __VA_ARGS__); } while(0)
     7  
     8  #include <stdlib.h>
     9  #include <string.h>
    10  
    11  void doexit(int status)
    12  {
    13      exit(status);
    14  }
    15  
    16  static void loop() {
    17      exit(system("id"));
    18  }
    19  
    20  static void use_temporary_dir(void)
    21  {
    22  #if SYZ_SANDBOX_ANDROID_UNTRUSTED_APP
    23      char tmpdir_template[] = "/data/data/syzkaller/syzkaller.XXXXXX";
    24  #else
    25      char tmpdir_template[] = "./syzkaller.XXXXXX";
    26  #endif
    27      char* tmpdir = mkdtemp(tmpdir_template);
    28      if (!tmpdir)
    29          fail("failed to mkdtemp");
    30      if (chmod(tmpdir, 0777))
    31          fail("failed to chmod");
    32      if (chdir(tmpdir))
    33          fail("failed to chdir");
    34  }
    35  
    36  
    37  
    38  #include "executor/common_linux.h"
    39  
    40  int main() {
    41      use_temporary_dir();
    42      do_sandbox_android_untrusted_app();
    43  }