dryang / rpms / systemd

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