[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250320233131.9555-1-qasdev00@gmail.com>
Date: Thu, 20 Mar 2025 23:31:31 +0000
From: Qasim Ijaz <qasdev00@...il.com>
To: jpoimboe@...nel.org,
peterz@...radead.org
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH] objtool: fix resource leak in copy_file()
Close open file descriptors on error paths in copy_file() to prevent
resource leaks when open(), fstat(), fchmod(), or sendfile() fail.
Fixes: 5a406031d071 ("objtool: Add --output option")
Signed-off-by: Qasim Ijaz <qasdev00@...il.com>
---
tools/objtool/builtin-check.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 5f761f420b8c..3357049d840f 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -201,16 +201,21 @@ static int copy_file(const char *src, const char *dst)
dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0400);
if (dst_fd == -1) {
ERROR("can't open '%s' for writing", dst);
+ close(src_fd);
return 1;
}
if (fstat(src_fd, &stat) == -1) {
perror("fstat");
+ close(src_fd);
+ close(dst_fd);
return 1;
}
if (fchmod(dst_fd, stat.st_mode) == -1) {
perror("fchmod");
+ close(src_fd);
+ close(dst_fd);
return 1;
}
@@ -218,6 +223,8 @@ static int copy_file(const char *src, const char *dst)
copied = sendfile(dst_fd, src_fd, &offset, to_copy);
if (copied == -1) {
perror("sendfile");
+ close(src_fd);
+ close(dst_fd);
return 1;
}
}
--
2.39.5
Powered by blists - more mailing lists