Skip to content

Commit 3b2c2ab

Browse files
techyguyperplexablemhiramat
authored andcommitted
tools/bootconfig: fix fd leak in load_xbc_file() on fstat failure
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/[email protected]/ Fixes: 950313e ("tools: bootconfig: Add bootconfig command") Signed-off-by: Josh Law <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent bb288d7 commit 3b2c2ab

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
@@ -162,8 +162,11 @@ static int load_xbc_file(const char *path, char **buf)
162162
if (fd < 0)
163163
return -errno;
164164
ret = fstat(fd, &stat);
165-
if (ret < 0)
166-
return -errno;
165+
if (ret < 0) {
166+
ret = -errno;
167+
close(fd);
168+
return ret;
169+
}
167170

168171
ret = load_xbc_fd(fd, buf, stat.st_size);
169172

0 commit comments

Comments
 (0)