Skip to contentSkip to conversation

tools/fit_image.c: Update some return code paths

PATCH In review Tom Rini 1 participant 2 messages Sep 27, 2017 – Oct 7, 2017

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 tools/fit_image.c: Update some return code paths

Coverity has found some problems with the return paths in parts of this code. We have a case where we were going to the wrong part of the unwind (open() failed so we cannot close the fd), a case where we were only free()ing our buf on the error path and finally a case where we did not munmap in the failure path.

Reported-by Coverity (CID: 138492, 138495, 143064)
---
 tools/fit_image.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/fit_image.c +3 -1
index 4dc8bd886245..c6026567f3a6 100644
@@ -372,7 +372,7 @@ static int fit_build(struct image_tool_params *params, const char *fname)
 	if (fd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			params->cmdname, fname, strerror(errno));
-		goto err;
+		goto err_buf;
 	}
 	ret = write(fd, buf, size);
 	if (ret != size) {
@@ -501,6 +501,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 		ret = -EIO;
 		goto err;
 	}
+	free(buf);
 	close(fd);
 	return 0;
 
@@ -601,6 +602,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 	ret = 0;
 
 err:
+	munmap(old_fdt, sbuf.st_size);
 	free(fdt);
 	close(fd);
 	return ret;
Signature · 1 line
1.9.1
author
#1 lore raw
Quoted 8 lines · Tom Rini

Coverity has found some problems with the return paths in parts of this code. We have a case where we were going to the wrong part of the unwind (open() failed so we cannot close the fd), a case where we were only free()ing our buf on the error path and finally a case where we did not munmap in the failure path.

Reported-by Coverity (CID: 138492, 138495, 143064)

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171007/e34fe500/attachment.sig>