]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fuzz: Add an XDG desktop file fuzzer 15226/head
authorBenjamin Berg <bberg@redhat.com>
Tue, 31 Mar 2020 14:16:27 +0000 (16:16 +0200)
committerBenjamin Berg <bberg@redhat.com>
Wed, 27 May 2020 07:02:10 +0000 (09:02 +0200)
To test the XDG parser used by the xdg-autostart-generator.

Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru>
src/fuzz/fuzz-xdg-desktop.c [new file with mode: 0644]
src/fuzz/meson.build
test/fuzz/fuzz-xdg-desktop/full.desktop [new file with mode: 0644]
test/fuzz/fuzz-xdg-desktop/org.gnome.SettingsDaemon.Power.desktop [new file with mode: 0644]
test/fuzz/fuzz-xdg-desktop/valid.desktop [new file with mode: 0644]

diff --git a/src/fuzz/fuzz-xdg-desktop.c b/src/fuzz/fuzz-xdg-desktop.c
new file mode 100644 (file)
index 0000000..8c6472b
--- /dev/null
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "fs-util.h"
+#include "rm-rf.h"
+#include "string-util.h"
+#include "strv.h"
+#include "tests.h"
+#include "tmpfile-util.h"
+#include "fuzz.h"
+#include "xdg-autostart-service.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+        _cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-xdg-desktop.XXXXXX";
+        _cleanup_close_ int fd = -1;
+        _cleanup_(xdg_autostart_service_freep) XdgAutostartService *service = NULL;
+        _cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
+
+        /* 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);
+
+        assert_se(mkdtemp_malloc("/tmp/fuzz-xdg-desktop-XXXXXX", &tmpdir) >= 0);
+
+        fd = mkostemp_safe(name);
+        assert_se(fd >= 0);
+        assert_se(write(fd, data, size) == (ssize_t) size);
+
+        assert_se(service = xdg_autostart_service_parse_desktop(name));
+        assert_se(service->name = strdup("fuzz-xdg-desktop.service"));
+        if (service)
+                (void) xdg_autostart_service_generate_unit(service, tmpdir);
+
+        return 0;
+}
index c88812d1de9f7d83a26f7e9c52d19ac875179007..01f119fcd0b374586ba98979b3a87aec77065c77 100644 (file)
@@ -146,4 +146,10 @@ fuzzers += [
         [['src/fuzz/fuzz-time-util.c'],
          [libshared],
          []],
+
+        [['src/fuzz/fuzz-xdg-desktop.c',
+          'src/xdg-autostart-generator/xdg-autostart-service.h',
+          'src/xdg-autostart-generator/xdg-autostart-service.c'],
+         [],
+         []],
 ]
diff --git a/test/fuzz/fuzz-xdg-desktop/full.desktop b/test/fuzz/fuzz-xdg-desktop/full.desktop
new file mode 100644 (file)
index 0000000..e5da36b
--- /dev/null
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Type=Application
+Name=GNOME Settings Daemon's power plugin
+Exec=/usr/bin/sleep %i %f "%F" "--test" ";\\\\!?"
+OnlyShowIn=GNOME;
+NoDisplay=true
+X-GNOME-Autostart-Phase=Initialization
+X-GNOME-Autostart-Notify=true
+X-GNOME-AutoRestart=true
+X-GNOME-HiddenUnderSystemd=true
diff --git a/test/fuzz/fuzz-xdg-desktop/org.gnome.SettingsDaemon.Power.desktop b/test/fuzz/fuzz-xdg-desktop/org.gnome.SettingsDaemon.Power.desktop
new file mode 100644 (file)
index 0000000..9d3e0c5
--- /dev/null
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Type=Application
+Name=GNOME Settings Daemon's power plugin
+Exec=/usr/libexec/gsd-power
+OnlyShowIn=GNOME;
+NoDisplay=true
+X-GNOME-Autostart-Phase=Initialization
+X-GNOME-Autostart-Notify=true
+X-GNOME-AutoRestart=true
+X-GNOME-HiddenUnderSystemd=true
diff --git a/test/fuzz/fuzz-xdg-desktop/valid.desktop b/test/fuzz/fuzz-xdg-desktop/valid.desktop
new file mode 100644 (file)
index 0000000..20fb5fe
--- /dev/null
@@ -0,0 +1,12 @@
+Desktop Entry
+Name=
+Exec=
+TryExec=
+Type=
+OnlyShowIn=
+NotShowIn=
+Hidden=
+AutostartCondition=
+X-KDE-autostart-condition=
+X-GNOME-Autostart-Phase=
+X-GNOME-HiddenUnderSystemd=