Blame SOURCES/0264-fuzz-journal-stream-avoid-assertion-failure-on-sampl.patch

ddca0b
From 2d197adc6d7109d5901401a90288530582f3f991 Mon Sep 17 00:00:00 2001
ddca0b
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
ddca0b
Date: Tue, 26 Feb 2019 13:00:35 +0100
ddca0b
Subject: [PATCH] fuzz-journal-stream: avoid assertion failure on samples which
ddca0b
 don't fit in pipe
ddca0b
MIME-Version: 1.0
ddca0b
Content-Type: text/plain; charset=UTF-8
ddca0b
Content-Transfer-Encoding: 8bit
ddca0b
ddca0b
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11587.
ddca0b
We had a sample which was large enough that write(2) failed to push all the
ddca0b
data into the pipe, and an assert failed. The code could be changed to use
ddca0b
a loop, but then we'd need to interleave writes and sd_event_run (to process
ddca0b
the journal). I don't think the complexity is worth it — fuzzing works best
ddca0b
if the sample is not too huge anyway. So let's just reject samples above 64k,
ddca0b
and tell oss-fuzz about this limit.
ddca0b
ddca0b
(cherry picked from commit eafadd069c4e30ed62173123326a7237448615d1)
ddca0b
ddca0b
Resolves: #1764560
ddca0b
---
ddca0b
 src/fuzz/fuzz-journald-stream.c       | 2 +-
ddca0b
 src/fuzz/fuzz-journald-stream.options | 2 ++
ddca0b
 2 files changed, 3 insertions(+), 1 deletion(-)
ddca0b
 create mode 100644 src/fuzz/fuzz-journald-stream.options
ddca0b
ddca0b
diff --git a/src/fuzz/fuzz-journald-stream.c b/src/fuzz/fuzz-journald-stream.c
ddca0b
index 247c0889bc..693b197d3a 100644
ddca0b
--- a/src/fuzz/fuzz-journald-stream.c
ddca0b
+++ b/src/fuzz/fuzz-journald-stream.c
ddca0b
@@ -14,7 +14,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
ddca0b
         StdoutStream *stream;
ddca0b
         int v;
ddca0b
 
ddca0b
-        if (size == 0)
ddca0b
+        if (size == 0 || size > 65536)
ddca0b
                 return 0;
ddca0b
 
ddca0b
         if (!getenv("SYSTEMD_LOG_LEVEL"))
ddca0b
diff --git a/src/fuzz/fuzz-journald-stream.options b/src/fuzz/fuzz-journald-stream.options
ddca0b
new file mode 100644
ddca0b
index 0000000000..678d526b1e
ddca0b
--- /dev/null
ddca0b
+++ b/src/fuzz/fuzz-journald-stream.options
ddca0b
@@ -0,0 +1,2 @@
ddca0b
+[libfuzzer]
ddca0b
+max_len = 65536