[PATCH master 3/3] sandbox: fix use of initialized variable in error path

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Mar 22 06:55:27 GMT 2021


fd could be uninitialized in some error paths. Give it a value that
close can be called on without adverse effect.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/os/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index fd75cc04cc16..d09604af1400 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -321,7 +321,7 @@ int linux_open_hostfile(struct hf_info *hf)
 {
 	char *buf = NULL;
 	struct stat s;
-	int fd;
+	int fd = -1;
 
 	printf("add %s %sbacked by file %s%s\n", hf->devname,
 	       hf->filename ? "" : "initially un", hf->filename ?: "",
@@ -408,7 +408,7 @@ int linux_open_hostfile(struct hf_info *hf)
 	return 0;
 
 err_out:
-	if (fd > 0)
+	if (fd >= 0)
 		close(fd);
 	free(buf);
 	return -1;
-- 
2.29.2




More information about the barebox mailing list