fuzz-journal-remote: remove temporary files on exit

This commit is contained in:
Yu Watanabe
2023-03-18 20:29:56 +09:00
parent 0bc2bcf4fe
commit 7b60f72cdd
+8 -1
View File
@@ -13,13 +13,17 @@
#include "journal-remote.h"
#include "logs-show.h"
#include "memfd-util.h"
#include "path-util.h"
#include "rm-rf.h"
#include "strv.h"
#include "tmpfile-util.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int fdin;
void *mem;
_cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-journal-remote.XXXXXX.journal";
_cleanup_close_ int fdout = -EBADF;
_cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
_cleanup_(unlink_and_freep) char *name = NULL;
_cleanup_(sd_journal_closep) sd_journal *j = NULL;
_cleanup_(journal_remote_server_destroy) RemoteServer s = {};
int r;
@@ -30,6 +34,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (!getenv("SYSTEMD_LOG_LEVEL"))
log_set_max_level(LOG_ERR);
assert_se(mkdtemp_malloc("/tmp/fuzz-journal-remote-XXXXXX", &tmp) >= 0);
assert_se(name = path_join(tmp, "fuzz-journal-remote.XXXXXX.journal"));
fdin = memfd_new_and_map("fuzz-journal-remote", size, &mem);
if (fdin < 0)
return log_error_errno(fdin, "memfd_new_and_map() failed: %m");