1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "alloc-util.h"
7 #include "string-util.h"
10 #include "tmpfile-util.h"
12 #include "xdg-autostart-service.h"
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
;
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
);
25 assert_se(mkdtemp_malloc("/tmp/fuzz-xdg-desktop-XXXXXX", &tmpdir
) >= 0);
27 fd
= mkostemp_safe(name
);
29 assert_se(write(fd
, data
, size
) == (ssize_t
) size
);
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
);