mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 12:53:14 +01:00
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: 950313ebf7 ("tools: bootconfig: Add bootconfig command")
Signed-off-by: Josh Law <[email protected]>
Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
This commit is contained in:
1 parent
bb288d7d86
commit
3b2c2ab4ce
1 file changed
+5
-2
@@ -162,8 +162,11 @@ static int load_xbc_file(const char *path, char **buf)
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
ret = fstat(fd, &stat);
|
||||
if (ret < 0)
|
||||
return -errno;
|
||||
if (ret < 0) {
|
||||
ret = -errno;
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = load_xbc_fd(fd, buf, stat.st_size);
|
||||
|
||||
|
||||
Reference in new issue
Block a user