mirror of
https://github.com/systemd/systemd.git
synced 2024-12-01 06:13:38 +08:00
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.
This commit is contained in:
parent
8e96f161af
commit
fa6e5861f7
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user