]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fuzz: add nspawn-settings fuzzer
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 11 Mar 2019 11:43:20 +0000 (12:43 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 11 Mar 2019 13:13:00 +0000 (14:13 +0100)
src/fuzz/fuzz-nspawn-settings.c [new file with mode: 0644]
src/fuzz/meson.build
test/fuzz/fuzz-nspawn-settings/basic-config [new file with mode: 0644]

diff --git a/src/fuzz/fuzz-nspawn-settings.c b/src/fuzz/fuzz-nspawn-settings.c
new file mode 100644 (file)
index 0000000..6c81eb7
--- /dev/null
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include <errno.h>
+
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "fuzz.h"
+#include "nspawn-settings.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+        _cleanup_fclose_ FILE *f = NULL;
+        _cleanup_(settings_freep) Settings *s = NULL;
+
+        if (size == 0)
+                return 0;
+
+        f = fmemopen((char*) data, size, "re");
+        assert_se(f);
+
+        /* 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"))
+                log_set_max_level(LOG_CRIT);
+
+        (void) settings_load(f, "/dev/null", &s);
+
+        return 0;
+}
index e851d4e764037f9b66abf40918ea8eb78b35ef60..4a242f8a6ce17917c2e656612ce6ca8a7ea50e75 100644 (file)
@@ -124,4 +124,9 @@ fuzzers += [
         [['src/fuzz/fuzz-hostname-util.c'],
          [libshared],
          []],
+
+        [['src/fuzz/fuzz-nspawn-settings.c'],
+         [libshared,
+          libnspawn_core],
+         []],
 ]
diff --git a/test/fuzz/fuzz-nspawn-settings/basic-config b/test/fuzz/fuzz-nspawn-settings/basic-config
new file mode 100644 (file)
index 0000000..be0d4e7
--- /dev/null
@@ -0,0 +1,36 @@
+[Exec]
+Boot=off
+ProcessTwo=off
+Parameters=/sbin/init -x=1
+Environment=THIS=that
+User=user
+WorkingDirectory=/cwd
+PivotRoot=/newroot
+Capability=CAP_NET
+DropCapability=CAP_ADMIN
+KillSignal=SIGTERM
+Personality=shy
+MachineID=edbfea3309ba41ea83e2318c58a8d498
+PrivateUser=1:2
+NotifyReady=no
+SystemCallFilters=write
+
+[Files]
+ReadOnly=no
+Volatile=no
+Bind=/bindthis
+BindReadOnly=/bindthisro
+TemporaryFileSystem=/thisismytmpfs:rw
+Overlay=/thisisanoverlay:/thisisanoverlaytoo
+PrivateUsersChown=no
+
+[Network]
+Private=off
+VirtualEthernet=yes
+VirtualEthernetExtra=veth1:veth2
+Interface=eth1 enp0s1
+MacVLAN=eno1 eno2
+IPVLAN=eno3 enp2s124
+Bridge=bridge123 bridge125
+Zone=myzone
+Port=1234 156 -1