diff options
author | Luca Boccassi <bluca@debian.org> | 2023-04-27 01:05:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 01:05:01 +0200 |
commit | 2df327f6f6cdb95e086b2e698c59246abe5fa187 (patch) | |
tree | 8a451213de5dfa46840cc663d17edf78ce2a6420 /src | |
parent | Merge pull request #27355 from fbuihuu/kbd-improve-vc2x11-conversion (diff) | |
parent | fuzz-journal-remote: fix potential fd-leak (diff) | |
download | systemd-2df327f6f6cdb95e086b2e698c59246abe5fa187.tar.xz systemd-2df327f6f6cdb95e086b2e698c59246abe5fa187.zip |
Merge pull request #26877 from yuwata/fuzz-journal-remote
fuzz-journal-remote: several cleanups
Diffstat (limited to 'src')
-rw-r--r-- | src/journal-remote/fuzz-journal-remote.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/journal-remote/fuzz-journal-remote.c b/src/journal-remote/fuzz-journal-remote.c index da0d83ec9a..ab4e731000 100644 --- a/src/journal-remote/fuzz-journal-remote.c +++ b/src/journal-remote/fuzz-journal-remote.c @@ -13,16 +13,19 @@ #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_close_ int fdin_close = -EBADF, 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; + void *mem; + int fdin, r; if (outside_size_range(size, 3, 65536)) return 0; @@ -30,7 +33,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (!getenv("SYSTEMD_LOG_LEVEL")) log_set_max_level(LOG_ERR); - fdin = memfd_new_and_map("fuzz-journal-remote", size, &mem); + assert_se(mkdtemp_malloc("/tmp/fuzz-journal-remote-XXXXXX", &tmp) >= 0); + assert_se(name = path_join(tmp, "fuzz-journal-remote.XXXXXX.journal")); + + fdin = fdin_close = memfd_new_and_map("fuzz-journal-remote", size, &mem); if (fdin < 0) return log_error_errno(fdin, "memfd_new_and_map() failed: %m"); @@ -50,10 +56,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { } r = journal_remote_add_source(&s, fdin, (char*) "fuzz-data", false); - if (r < 0) { - safe_close(fdin); + if (r < 0) return r; - } + TAKE_FD(fdin_close); assert(r > 0); while (s.active) |