summaryrefslogtreecommitdiff
path: root/src/xdg-autostart-generator
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-12-31 04:30:43 +0900
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-12 13:31:11 +0200
commit7593691aadc7e1e9c5f17fd26424abe337d56302 (patch)
tree679f27ca634c56508788eee6d3809c71c1c48005 /src/xdg-autostart-generator
parent96974ea4a85bee508659f8c36f6a32c6b89646f4 (diff)
downloadsystemd-7593691aadc7e1e9c5f17fd26424abe337d56302.tar.gz
fuzzers: add input size limits, always configure limits in two ways
Without the size limits, oss-fuzz creates huge samples that time out. Usually this is because some of our code has bad algorithmic complexity. For data like configuration samples we don't need to care about this: non-rogue configs are rarely more than a few items, and a bit of a slowdown with a few hundred items is acceptable. This wouldn't be OK for processing of untrusted data though. We need to set the limit in two ways: through .options and in the code. The first because it nicely allows libFuzzer to avoid wasting time, and the second because fuzzers like hongfuzz and afl don't support .options. While at it, let's fix an off-by-one (65535 is the largest offset for a power-of-two size, but we're checking the size here). Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Diffstat (limited to 'src/xdg-autostart-generator')
-rw-r--r--src/xdg-autostart-generator/fuzz-xdg-desktop.c3
-rw-r--r--src/xdg-autostart-generator/fuzz-xdg-desktop.options2
2 files changed, 5 insertions, 0 deletions
diff --git a/src/xdg-autostart-generator/fuzz-xdg-desktop.c b/src/xdg-autostart-generator/fuzz-xdg-desktop.c
index 52ba7ff0a4..0ae27fc39d 100644
--- a/src/xdg-autostart-generator/fuzz-xdg-desktop.c
+++ b/src/xdg-autostart-generator/fuzz-xdg-desktop.c
@@ -17,6 +17,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(xdg_autostart_service_freep) XdgAutostartService *service = NULL;
_cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
+ if (size > 65536)
+ return 0;
+
/* We don't want to fill the logs with messages about parse errors.
* Disable most logging if not running standalone */
if (!getenv("SYSTEMD_LOG_LEVEL"))
diff --git a/src/xdg-autostart-generator/fuzz-xdg-desktop.options b/src/xdg-autostart-generator/fuzz-xdg-desktop.options
new file mode 100644
index 0000000000..678d526b1e
--- /dev/null
+++ b/src/xdg-autostart-generator/fuzz-xdg-desktop.options
@@ -0,0 +1,2 @@
+[libfuzzer]
+max_len = 65536