]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-xdg-desktop.c
journalctl: make pcre2 a dlopen() dependency
[thirdparty/systemd.git] / src / fuzz / fuzz-xdg-desktop.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "alloc-util.h"
4 #include "fd-util.h"
5 #include "fs-util.h"
6 #include "rm-rf.h"
7 #include "string-util.h"
8 #include "strv.h"
9 #include "tests.h"
10 #include "tmpfile-util.h"
11 #include "fuzz.h"
12 #include "xdg-autostart-service.h"
13
14 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
15 _cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-xdg-desktop.XXXXXX";
16 _cleanup_close_ int fd = -1;
17 _cleanup_(xdg_autostart_service_freep) XdgAutostartService *service = NULL;
18 _cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
19
20 /* We don't want to fill the logs with messages about parse errors.
21 * Disable most logging if not running standalone */
22 if (!getenv("SYSTEMD_LOG_LEVEL"))
23 log_set_max_level(LOG_CRIT);
24
25 assert_se(mkdtemp_malloc("/tmp/fuzz-xdg-desktop-XXXXXX", &tmpdir) >= 0);
26
27 fd = mkostemp_safe(name);
28 assert_se(fd >= 0);
29 assert_se(write(fd, data, size) == (ssize_t) size);
30
31 assert_se(service = xdg_autostart_service_parse_desktop(name));
32 assert_se(service->name = strdup("fuzz-xdg-desktop.service"));
33 (void) xdg_autostart_service_generate_unit(service, tmpdir);
34
35 return 0;
36 }