summaryrefslogtreecommitdiffstats
path: root/src/fuzz
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2018-11-28 01:29:57 +0100
committerEvgeny Vereshchagin <evvers@ya.ru>2018-11-28 01:34:38 +0100
commitfa6e5861f77d621b5a23fa9758b8ade47b0b3c0e (patch)
treeb2b8980bfb911933844de5124e0a7875c1704630 /src/fuzz
parenttests: keep going even if setup_mount_namespace has failed (diff)
downloadsystemd-fa6e5861f77d621b5a23fa9758b8ade47b0b3c0e.tar.xz
systemd-fa6e5861f77d621b5a23fa9758b8ade47b0b3c0e.zip
tests: make fuzz-udev-rules work also in the environment created by run_minijail
This should close https://oss-fuzz.com/testcase?key=5642013043589120. See also https://github.com/google/oss-fuzz/issues/1983.
Diffstat (limited to 'src/fuzz')
-rw-r--r--src/fuzz/fuzz-udev-rules.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/fuzz/fuzz-udev-rules.c b/src/fuzz/fuzz-udev-rules.c
index 5889bbe1a8..dbdcda329e 100644
--- a/src/fuzz/fuzz-udev-rules.c
+++ b/src/fuzz/fuzz-udev-rules.c
@@ -16,15 +16,16 @@
#include "tests.h"
#include "udev.h"
-static const struct fakefs {
+static struct fakefs {
const char *target;
bool ignore_mount_error;
+ bool is_mounted;
} fakefss[] = {
- { "/sys", false },
- { "/dev", false },
- { "/run", false },
- { "/etc", false },
- { UDEVLIBEXECDIR "/rules.d", true },
+ { "/sys", false, false },
+ { "/dev", false, false },
+ { "/run", false, false },
+ { "/etc", false, false },
+ { UDEVLIBEXECDIR "/rules.d", true, false },
};
static int setup_mount_namespace(void) {
@@ -45,23 +46,30 @@ static int setup_mount_namespace(void) {
}
static int setup_fake_filesystems(const char *runtime_dir) {
- for (unsigned i = 0; i < ELEMENTSOF(fakefss); i++)
+ for (unsigned i = 0; i < ELEMENTSOF(fakefss); i++) {
if (mount(runtime_dir, fakefss[i].target, NULL, MS_BIND, NULL) < 0) {
log_full_errno(fakefss[i].ignore_mount_error ? LOG_DEBUG : LOG_ERR, errno, "Failed to mount %s: %m", fakefss[i].target);
if (!fakefss[i].ignore_mount_error)
return -errno;
- }
+ } else
+ fakefss[i].is_mounted = true;
+ }
return 0;
}
static int cleanup_fake_filesystems(const char *runtime_dir) {
- for (unsigned i = 0; i < ELEMENTSOF(fakefss); i++)
+ for (unsigned i = 0; i < ELEMENTSOF(fakefss); i++) {
+ if (!fakefss[i].is_mounted)
+ continue;
+
if (umount(fakefss[i].target) < 0) {
log_full_errno(fakefss[i].ignore_mount_error ? LOG_DEBUG : LOG_ERR, errno, "Failed to umount %s: %m", fakefss[i].target);
if (!fakefss[i].ignore_mount_error)
return -errno;
- }
+ } else
+ fakefss[i].is_mounted = false;
+ }
return 0;
}
@@ -70,8 +78,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
FILE *f = NULL;
- /* To judge from https://oss-fuzz.com/testcase?key=5642013043589120, unshare/mount can fail.
- * It isn't critical so let's ignore it for now to see how it goes */
(void) setup_mount_namespace();
assert_se(runtime_dir = setup_fake_runtime_dir());
@@ -79,8 +85,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (setup_fake_filesystems(runtime_dir) < 0) {
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
return EXIT_TEST_SKIP;
-#else
- abort();
#endif
}