summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-18 12:29:27 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-18 12:29:56 +0100
commit9b72eacad2e23b5916f37c62f20a56b91b257344 (patch)
tree27c2db4a1bccf4952f38f271242fa7c0652357e1
parentfuzz-journal-remote: remove temporary files on exit (diff)
downloadsystemd-9b72eacad2e23b5916f37c62f20a56b91b257344.tar.xz
systemd-9b72eacad2e23b5916f37c62f20a56b91b257344.zip
fuzz-journal-remote: fix potential fd-leak
-rw-r--r--src/journal-remote/fuzz-journal-remote.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/journal-remote/fuzz-journal-remote.c b/src/journal-remote/fuzz-journal-remote.c
index ac71a33f7b..ab4e731000 100644
--- a/src/journal-remote/fuzz-journal-remote.c
+++ b/src/journal-remote/fuzz-journal-remote.c
@@ -19,14 +19,13 @@
#include "tmpfile-util.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
- int fdin;
- void *mem;
- _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;
@@ -37,7 +36,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
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);
+ 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");
@@ -57,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)