1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

Merge pull request #23310 from keszybz/suppress-fuzzer-timeouts-and-errors

Suppress fuzzer timeouts and errors
This commit is contained in:
Yu Watanabe 2022-05-09 15:50:29 +09:00 committed by GitHub
commit df423851fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 66 additions and 62 deletions

View File

@ -143,12 +143,13 @@ static Virtualization detect_vm_device_tree(void) {
#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch64)
static Virtualization detect_vm_dmi_vendor(void) {
static const char *const dmi_vendors[] = {
static const char* const dmi_vendors[] = {
"/sys/class/dmi/id/product_name", /* Test this before sys_vendor to detect KVM over QEMU */
"/sys/class/dmi/id/sys_vendor",
"/sys/class/dmi/id/board_vendor",
"/sys/class/dmi/id/bios_vendor",
"/sys/class/dmi/id/product_version" /* For Hyper-V VMs test */
"/sys/class/dmi/id/product_version", /* For Hyper-V VMs test */
NULL
};
static const struct {
@ -172,10 +173,10 @@ static Virtualization detect_vm_dmi_vendor(void) {
};
int r;
for (size_t i = 0; i < ELEMENTSOF(dmi_vendors); i++) {
STRV_FOREACH(vendor, dmi_vendors) {
_cleanup_free_ char *s = NULL;
r = read_one_line_file(dmi_vendors[i], &s);
r = read_one_line_file(*vendor, &s);
if (r < 0) {
if (r == -ENOENT)
continue;
@ -183,10 +184,10 @@ static Virtualization detect_vm_dmi_vendor(void) {
return r;
}
for (size_t j = 0; j < ELEMENTSOF(dmi_vendor_table); j++)
if (startswith(s, dmi_vendor_table[j].vendor)) {
log_debug("Virtualization %s found in DMI (%s)", s, dmi_vendors[i]);
return dmi_vendor_table[j].id;
for (size_t i = 0; i < ELEMENTSOF(dmi_vendor_table); i++)
if (startswith(s, dmi_vendor_table[i].vendor)) {
log_debug("Virtualization %s found in DMI (%s)", s, *vendor);
return dmi_vendor_table[i].id;
}
}
log_debug("No virtualization found in DMI vendor table.");

View File

@ -3655,7 +3655,7 @@ static bool generator_path_any(const char* const* paths) {
/* Optimize by skipping the whole process by not creating output directories
* if no generators are found. */
STRV_FOREACH(path, (char**) paths)
STRV_FOREACH(path, paths)
if (access(*path, F_OK) == 0)
found = true;
else if (errno != ENOENT)

View File

@ -372,12 +372,11 @@ static int strv_pair_to_json(char **l, JsonVariant **ret) {
static void strv_pair_print(char **l, const char *prefix) {
assert(prefix);
STRV_FOREACH_PAIR(p, q, l) {
STRV_FOREACH_PAIR(p, q, l)
if (p == l)
printf("%s %s=%s\n", prefix, *p, *q);
else
printf("%*s %s=%s\n", (int) strlen(prefix), "", *p, *q);
}
}
static int get_sysext_scopes(DissectedImage *m, char ***ret_scopes) {

View File

@ -66,7 +66,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
r = sd_journal_open_files(&j, (const char**) STRV_MAKE(name), 0);
if (r < 0) {
log_error_errno(r, "sd_journal_open_files([\"%s\"]) failed: %m", name);
assert_se(IN_SET(r, -ENOMEM, -EMFILE, -ENFILE));
assert_se(IN_SET(r, -ENOMEM, -EMFILE, -ENFILE, -ENODATA));
return r;
}

View File

@ -62,7 +62,7 @@ static int option_append(uint8_t options[], size_t size, size_t *offset,
if (strv_isempty((char **) optval))
return -EINVAL;
STRV_FOREACH(s, (char **) optval) {
STRV_FOREACH(s, (const char* const*) optval) {
size_t len = strlen(*s);
if (len > 255 || len == 0)
@ -78,7 +78,7 @@ static int option_append(uint8_t options[], size_t size, size_t *offset,
options[*offset + 1] = total;
*offset += 2;
STRV_FOREACH(s, (char **) optval) {
STRV_FOREACH(s, (const char* const*) optval) {
size_t len = strlen(*s);
options[*offset] = len;

View File

@ -1016,7 +1016,7 @@ int boot_config_augment_from_loader(
if (!c)
return log_oom();
STRV_FOREACH_PAIR(a, b, (char**) title_table)
STRV_FOREACH_PAIR(a, b, title_table)
if (streq(*a, *i)) {
t = strdup(*b);
if (!t)

View File

@ -76,26 +76,21 @@ static int component_compare(CalendarComponent * const *a, CalendarComponent * c
}
static void normalize_chain(CalendarComponent **c) {
CalendarComponent **b, *i, **j, *next;
size_t n = 0, k;
assert(c);
for (i = *c; i; i = i->next) {
size_t n = 0;
for (CalendarComponent *i = *c; i; i = i->next) {
n++;
/*
* While we're counting the chain, also normalize `stop`
* so the length of the range is a multiple of `repeat`
*/
/* While we're counting the chain, also normalize 'stop'
* so the length of the range is a multiple of 'repeat'. */
if (i->stop > i->start && i->repeat > 0)
i->stop -= (i->stop - i->start) % i->repeat;
/* If a repeat value is specified, but it cannot even be triggered once, let's suppress
* it.
/* If a repeat value is specified, but it cannot even be triggered once, let's suppress it.
*
* Similar, if the stop value is the same as the start value, then let's just make this a
* non-repeating chain element */
* Similarly, if the stop value is the same as the start value, then let's just make this a
* non-repeating chain element. */
if ((i->stop > i->start && i->repeat > 0 && i->start + i->repeat > i->stop) ||
i->start == i->stop) {
i->repeat = 0;
@ -106,17 +101,18 @@ static void normalize_chain(CalendarComponent **c) {
if (n <= 1)
return;
j = b = newa(CalendarComponent*, n);
for (i = *c; i; i = i->next)
CalendarComponent **b, **j;
b = j = newa(CalendarComponent*, n);
for (CalendarComponent *i = *c; i; i = i->next)
*(j++) = i;
typesafe_qsort(b, n, component_compare);
b[n-1]->next = NULL;
next = b[n-1];
CalendarComponent *next = b[n-1];
/* Drop non-unique entries */
for (k = n-1; k > 0; k--) {
for (size_t k = n-1; k > 0; k--) {
if (component_compare(&b[k-1], &next) == 0) {
free(b[k-1]);
continue;
@ -253,7 +249,7 @@ static void format_weekdays(FILE *f, const CalendarSpec *c) {
"Thu",
"Fri",
"Sat",
"Sun"
"Sun",
};
int l, x;
@ -408,7 +404,7 @@ static int parse_weekdays(const char **p, CalendarSpec *c) {
{ "Saturday", 5 },
{ "Sat", 5 },
{ "Sunday", 6 },
{ "Sun", 6 }
{ "Sun", 6 },
};
int l = -1;

View File

@ -497,7 +497,7 @@ static int config_parse_many_files(
}
/* First read the first found main config file. */
STRV_FOREACH(fn, (char**) conf_files) {
STRV_FOREACH(fn, conf_files) {
r = config_parse(NULL, *fn, NULL, sections, lookup, table, flags, userdata, &st);
if (r < 0)
return r;

View File

@ -1317,7 +1317,9 @@ static int mount_partition(
if (!fstype)
return -EAFNOSUPPORT;
/* We are looking at an encrypted partition? This either means stacked encryption, or the caller didn't call dissected_image_decrypt() beforehand. Let's return a recognizable error for this case. */
/* We are looking at an encrypted partition? This either means stacked encryption, or the caller
* didn't call dissected_image_decrypt() beforehand. Let's return a recognizable error for this
* case. */
if (streq(fstype, "crypto_LUKS"))
return -EUNATCH;
@ -3031,31 +3033,31 @@ int mount_image_privately_interactively(
}
static const char *const partition_designator_table[] = {
[PARTITION_ROOT] = "root",
[PARTITION_ROOT_SECONDARY] = "root-secondary",
[PARTITION_ROOT_OTHER] = "root-other",
[PARTITION_USR] = "usr",
[PARTITION_USR_SECONDARY] = "usr-secondary",
[PARTITION_USR_OTHER] = "usr-other",
[PARTITION_HOME] = "home",
[PARTITION_SRV] = "srv",
[PARTITION_ESP] = "esp",
[PARTITION_XBOOTLDR] = "xbootldr",
[PARTITION_SWAP] = "swap",
[PARTITION_ROOT_VERITY] = "root-verity",
[PARTITION_ROOT_SECONDARY_VERITY] = "root-secondary-verity",
[PARTITION_ROOT_OTHER_VERITY] = "root-other-verity",
[PARTITION_USR_VERITY] = "usr-verity",
[PARTITION_USR_SECONDARY_VERITY] = "usr-secondary-verity",
[PARTITION_USR_OTHER_VERITY] = "usr-other-verity",
[PARTITION_ROOT_VERITY_SIG] = "root-verity-sig",
[PARTITION_ROOT] = "root",
[PARTITION_ROOT_SECONDARY] = "root-secondary",
[PARTITION_ROOT_OTHER] = "root-other",
[PARTITION_USR] = "usr",
[PARTITION_USR_SECONDARY] = "usr-secondary",
[PARTITION_USR_OTHER] = "usr-other",
[PARTITION_HOME] = "home",
[PARTITION_SRV] = "srv",
[PARTITION_ESP] = "esp",
[PARTITION_XBOOTLDR] = "xbootldr",
[PARTITION_SWAP] = "swap",
[PARTITION_ROOT_VERITY] = "root-verity",
[PARTITION_ROOT_SECONDARY_VERITY] = "root-secondary-verity",
[PARTITION_ROOT_OTHER_VERITY] = "root-other-verity",
[PARTITION_USR_VERITY] = "usr-verity",
[PARTITION_USR_SECONDARY_VERITY] = "usr-secondary-verity",
[PARTITION_USR_OTHER_VERITY] = "usr-other-verity",
[PARTITION_ROOT_VERITY_SIG] = "root-verity-sig",
[PARTITION_ROOT_SECONDARY_VERITY_SIG] = "root-secondary-verity-sig",
[PARTITION_ROOT_OTHER_VERITY_SIG] = "root-other-verity-sig",
[PARTITION_USR_VERITY_SIG] = "usr-verity-sig",
[PARTITION_USR_SECONDARY_VERITY_SIG] = "usr-secondary-verity-sig",
[PARTITION_USR_OTHER_VERITY_SIG] = "usr-other-verity-sig",
[PARTITION_TMP] = "tmp",
[PARTITION_VAR] = "var",
[PARTITION_ROOT_OTHER_VERITY_SIG] = "root-other-verity-sig",
[PARTITION_USR_VERITY_SIG] = "usr-verity-sig",
[PARTITION_USR_SECONDARY_VERITY_SIG] = "usr-secondary-verity-sig",
[PARTITION_USR_OTHER_VERITY_SIG] = "usr-other-verity-sig",
[PARTITION_TMP] = "tmp",
[PARTITION_VAR] = "var",
};
int verity_dissect_and_mount(

View File

@ -31,6 +31,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (!argv[0])
return 0; /* argv[0] should always be present, but may be zero-length. */
if (strv_length(argv) > 1024)
return 0; /* oss-fuzz reports timeouts which are caused by appending to a very long strv.
* The code is indeed not very efficient, but it's designed for normal command-line
* use, where we don't expect more than a dozen of entries. The fact that it is
* slow with ~100k entries is not particularly interesting. Let's just refuse such
* long command lines. */
if (getenv_bool("SYSTEMD_FUZZ_OUTPUT") <= 0) {
orig_stdout_fd = fcntl(fileno(stdout), F_DUPFD_CLOEXEC, 3);

View File

@ -712,7 +712,7 @@ TEST(rename_noreplace) {
j = strjoina(z, table[4]);
(void) symlink("foobar", j);
STRV_FOREACH(a, (char**) table) {
STRV_FOREACH(a, table) {
_cleanup_free_ char *x = NULL, *y = NULL;
x = strjoin(z, *a);
@ -723,7 +723,7 @@ TEST(rename_noreplace) {
continue;
}
STRV_FOREACH(b, (char**) table) {
STRV_FOREACH(b, table) {
_cleanup_free_ char *w = NULL;
w = strjoin(z, *b);

View File

@ -27,7 +27,7 @@ static const char* const cases[] = {
};
TEST(sysctl_normalize) {
STRV_FOREACH_PAIR(s, expected, (const char**) cases) {
STRV_FOREACH_PAIR(s, expected, cases) {
_cleanup_free_ char *t;
assert_se(t = strdup(*s));