Skip to content

Commit e3936f7

Browse files
techyguyperplexableopsiff
authored andcommitted
tools/bootconfig: fix fd leak in load_xbc_file() on fstat failure
[ Upstream commit 3b2c2ab4ceb82af484310c3087541eab00ea288b ] If fstat() fails after open() succeeds, the function returns without closing the file descriptor. Also preserve errno across close(), since close() may overwrite it before the error is returned. Link: https://lore.kernel.org/all/20260318155847.78065-3-objecting@objecting.org/ Fixes: 950313e ("tools: bootconfig: Add bootconfig command") Signed-off-by: Josh Law <objecting@objecting.org> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 2cf5eff223fc9b720690c16ab763a00788e85c4b) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 193c827 commit e3936f7

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

tools/bootconfig/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ static int load_xbc_file(const char *path, char **buf)
157157
if (fd < 0)
158158
return -errno;
159159
ret = fstat(fd, &stat);
160-
if (ret < 0)
161-
return -errno;
160+
if (ret < 0) {
161+
ret = -errno;
162+
close(fd);
163+
return ret;
164+
}
162165

163166
ret = load_xbc_fd(fd, buf, stat.st_size);
164167

0 commit comments

Comments
 (0)