X Tutup
Skip to content

Commit 0fb7292

Browse files
committed
fuzz: limit the maximum size of test inputs for a few parsers
We have a few cases or reported issues which are about a timeout to parse the input in 25 s. In all cases, the input is a few hundred kb. We don't really care if the config parsers are super efficent, so let's set a limit on the input size to avoid triggering such issues. The parsers often contain quadratic algorithms. This is OK, because the numbers of elements are almost always very small in real use. Rewriting the code to use more complicated data structures to speed this up would not only complicate the code, but also pessimize behaviour for the overwhelmingly common case of small samples. Note that in all those cases, the input data is trusted. We care about memory correctness, and not not so much about efficiency. The size checks are done twice: using options for libfuzzer, and using an internal check for afl. Those should be changed together. I didn't use a define, because there is no easy mechanism to share the define between the two files.
1 parent 6d632d0 commit 0fb7292

File tree

6 files changed

+13
-1
lines changed

6 files changed

+13
-1
lines changed

src/fuzz/fuzz-env-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
1212
_cleanup_fclose_ FILE *f = NULL;
1313
_cleanup_strv_free_ char **rl = NULL, **rlp = NULL;
1414

15-
if (size == 0)
15+
if (size == 0 || size > 65535)
1616
return 0;
1717

1818
f = fmemopen((char*) data, size, "re");

src/fuzz/fuzz-env-file.options

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[libfuzzer]
2+
max_len = 65535

src/network/fuzz-network-parser.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
1111
_cleanup_fclose_ FILE *f = NULL;
1212
_cleanup_(unlink_tempfilep) char network_config[] = "/tmp/fuzz-networkd.XXXXXX";
1313

14+
if (size > 65535)
15+
return 0;
16+
1417
if (!getenv("SYSTEMD_LOG_LEVEL"))
1518
log_set_max_level(LOG_CRIT);
1619

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[libfuzzer]
2+
max_len = 65535

src/udev/net/fuzz-link-parser.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
1111
_cleanup_(unlink_tempfilep) char filename[] = "/tmp/fuzz-link-config.XXXXXX";
1212
_cleanup_fclose_ FILE *f = NULL;
1313

14+
if (size > 65535)
15+
return 0;
16+
1417
if (!getenv("SYSTEMD_LOG_LEVEL"))
1518
log_set_max_level(LOG_CRIT);
1619

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[libfuzzer]
2+
max_len = 65535

0 commit comments

Comments
 (0)
X Tutup