Commit 3b2c2ab4 authored by Josh Law's avatar Josh Law Committed by Masami Hiramatsu (Google)
Browse files

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/20260318155847.78065-3-objecting@objecting.org/



Fixes: 950313eb ("tools: bootconfig: Add bootconfig command")
Signed-off-by: default avatarJosh Law <objecting@objecting.org>
Signed-off-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
parent bb288d7d
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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);