diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-05-31 11:16:40 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-06-03 10:06:46 +0000 |
| commit | 720b7efa99d7f3b4069af440ea7d004a6f27467d (patch) | |
| tree | a812d72870d72580cf4b902d00fc2e9cf14fd122 /executor/common_bsd.h | |
| parent | d2862abe19f233f936ad61550df88db5b41049c8 (diff) | |
executor: rework feature setup
Return failure reason from setup functions rather than crash.
This will provide better error messages, but also allow setup
w/o creating subprocesses which will be needed when we combine
fuzzer and executor.
Also close all resources created during setup.
This is also useful for in-process setup, but also should improve
chances of reproducing a bug with C reproducer. Currently leaked
file descriptors may disturb repro execution (e.g. it may act
on a wrong fd).
Diffstat (limited to 'executor/common_bsd.h')
| -rw-r--r-- | executor/common_bsd.h | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/executor/common_bsd.h b/executor/common_bsd.h index e0beac33f..683e7c140 100644 --- a/executor/common_bsd.h +++ b/executor/common_bsd.h @@ -18,11 +18,12 @@ #endif #if SYZ_EXECUTOR || SYZ_USB #include <dirent.h> -static void setup_usb(void) + +static const char* setup_usb(void) { DIR* dir = opendir("/dev"); if (dir == NULL) - fail("failed to open /dev"); + return "failed to open /dev"; bool have_vhci = false; struct dirent* ent = NULL; @@ -33,14 +34,14 @@ static void setup_usb(void) continue; char path[1024]; snprintf(path, sizeof(path), "/dev/%s", ent->d_name); - if (chmod(path, 0666)) - failmsg("failed to chmod vhci", "path=%s", path); + if (chmod(path, 0666)) { + closedir(dir); + return "failed to chmod /dev/vhci"; + } have_vhci = true; } - if (!have_vhci) - fail("don't have any /dev/vhci devices"); - closedir(dir); + return have_vhci ? NULL : "don't have any /dev/vhci devices"; } #endif @@ -48,11 +49,14 @@ static void setup_usb(void) #include <fcntl.h> #include <sys/fault.h> #include <sys/stat.h> -static void setup_fault(void) + +static const char* setup_fault(void) { if (chmod("/dev/fault", 0666)) - fail("failed to chmod /dev/fault"); + return "failed to chmod /dev/fault"; + return NULL; } + static int inject_fault(int nth) { struct fault_ioc_enable en; @@ -71,6 +75,7 @@ static int inject_fault(int nth) return fd; } #endif + #if SYZ_EXECUTOR static int fault_injected(int fd) { |
