Skip to contentSkip to conversation

dm: Fix various issues reported by coverity

PATCH New Simon Glass 3 participants 44 messages Mar 16, 2016 – Mar 23, 2016

lore
Share & tools
lore
#0 lore raw

cover dm: Fix various issues reported by coverity

A lot of issues have been found in the error handling with recent additions to the FIT handling code in mkimage. In some cases buffers are not freed or files are not closed. Fix these problems and a few others in existing code that coverity noticed due to recent patches.

Simon Glass (14):
mkimage: Fix munmap() call when importing data
mkimage: Correct file being closed twice in fit_import_data()
mkimage: Correct file being closed twice in fit_extract_data()
part_iso: Drop the customer unaligned access functions
part_efi: Drop the NULL check on dev_desc in part_print_efi()
part_efi: Drop NULL check in part_get_info_efi()
mkimage: Close the file when unable to get its size
mkimage: Add a missing free() to fit_import_data()
mkimage: Fix error path in fit_extract_data()
mkimage: Fix missing free() in fit_extract_data()
mkimage: Fix missing free() and close() in fit_build()
mkimage: Ensure file is closed in fdt_property_file()
mkimage: Don't close the file if it wasn't opened
usb: Correct return value in usb_stor_info()

 common/usb_storage.c |  2 +-
 disk/part_efi.c      |  6 +-----
 disk/part_iso.c      | 27 ++++-----------------------
 tools/fit_image.c    | 28 ++++++++++++++++++----------
 tools/imagetool.c    |  1 +
 5 files changed, 25 insertions(+), 39 deletions(-)
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#1 lore raw

PATCH 1/14 mkimage: Fix munmap() call when importing data

The munmap() call unmaps the wrong memory buffer. Fix it.

Reported-by Coverity (CID: 138505)
Reported-by Coverity (CID: 138495)

---

 tools/fit_image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/fit_image.c +1 -1
index 3ecc88f..2c8d92f 100644
@@ -517,7 +517,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 		}
 	}
 
-	munmap(fdt, sbuf.st_size);
+	munmap(old_fdt, sbuf.st_size);
 	close(fd);
 
 	/* Pack the FDT and place the data after it */
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#2 lore raw

PATCH 1/14 mkimage: Fix munmap() call when importing data

Quoted 5 lines · Simon Glass

The munmap() call unmaps the wrong memory buffer. Fix it.

Reported-by Coverity (CID: 138505)
Reported-by Coverity (CID: 138495)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/4aca066f/attachment.sig>
#3 lore raw

PATCH 1/14 mkimage: Fix munmap() call when importing data

In reply to Simon Glass
Quoted 6 lines · Simon Glass

The munmap() call unmaps the wrong memory buffer. Fix it.

Reported-by Coverity (CID: 138505)
Reported-by Coverity (CID: 138495)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/ba716eba/attachment.sig>
#4 lore raw

PATCH 2/14 mkimage: Correct file being closed twice in fit_import_data()

In reply to Simon Glass

The code flows through to the end of the function, so we don't need another close() before this. Remove it.

Reported-by Coverity (CID: 138504)

---

 tools/fit_image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/fit_image.c +1 -1
index 2c8d92f..31aa43c 100644
@@ -530,6 +530,7 @@ static int fit_import_data(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));
+		ret = -EIO;
 		goto err;
 	}
 	if (write(fd, fdt, new_size) != new_size) {
@@ -538,7 +539,6 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 		ret = -EIO;
 		goto err;
 	}
-	close(fd);
 
 	ret = 0;
 
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#5 lore raw

PATCH 2/14 mkimage: Correct file being closed twice in fit_import_data()

Quoted 6 lines · Simon Glass

The code flows through to the end of the function, so we don't need another close() before this. Remove it.

Reported-by Coverity (CID: 138504)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/0ef2a812/attachment.sig>
#6 lore raw

PATCH 2/14 mkimage: Correct file being closed twice in fit_import_data()

In reply to Simon Glass
Quoted 7 lines · Simon Glass

The code flows through to the end of the function, so we don't need another close() before this. Remove it.

Reported-by Coverity (CID: 138504)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/6970db11/attachment.sig>
#7 lore raw

PATCH 3/14 mkimage: Correct file being closed twice in fit_extract_data()

In reply to Simon Glass

The code flows through to the end of the function, so we don't need another close() before this. Remove it.

Reported-by Coverity (CID: 138503)

---

 tools/fit_image.c | 2 --
 1 file changed, 2 deletions(-)
tools/fit_image.c +0 -2
index 31aa43c..8a93ea3 100644
@@ -446,8 +446,6 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 		ret = -EIO;
 		goto err;
 	}
-	close(fd);
-
 	ret = 0;
 
 err:
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#8 lore raw

PATCH 3/14 mkimage: Correct file being closed twice in fit_extract_data()

Quoted 6 lines · Simon Glass

The code flows through to the end of the function, so we don't need another close() before this. Remove it.

Reported-by Coverity (CID: 138503)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/2b3d51c5/attachment.sig>
#9 lore raw

PATCH 3/14 mkimage: Correct file being closed twice in fit_extract_data()

In reply to Simon Glass
Quoted 7 lines · Simon Glass

The code flows through to the end of the function, so we don't need another close() before this. Remove it.

Reported-by Coverity (CID: 138503)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/0742f608/attachment.sig>
#10 lore raw

PATCH 4/14 part_iso: Drop the customer unaligned access functions

In reply to Simon Glass

One of these is causing a coverity warning. Drop these functions and use the standard U-Boot ones instead.

Reported-by Coverity (CID: 138499)

---

 disk/part_iso.c | 27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)
disk/part_iso.c +4 -23
index b83983b..2114faf 100644
@@ -7,6 +7,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <asm/unaligned.h>
 #include "part_iso.h"
 
 #ifdef HAVE_BLOCK_DEVICE
@@ -25,26 +26,6 @@
 
 static unsigned char tmpbuf[CD_SECTSIZE];
 
-/* Convert char[4] in little endian format to the host format integer
- */
-static inline unsigned long le32_to_int(unsigned char *le32)
-{
-    return ((le32[3] << 24) +
-	    (le32[2] << 16) +
-	    (le32[1] << 8) +
-	     le32[0]
-	   );
-}
-/* Convert char[2] in little endian format to the host format integer
- */
-static inline unsigned short le16_to_int(unsigned char *le16)
-{
-    return ((le16[1] << 8) +
-	   le16[0]
-	   );
-}
-
-
 /* only boot records will be listed as valid partitions */
 int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
 			   disk_partition_t *info, int verb)
@@ -103,7 +84,7 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
 				pbr->ident_str, dev_desc->devnum, part_num);
 		return (-1);
 	}
-	bootaddr=le32_to_int(pbr->pointer);
+	bootaddr = get_unaligned_le32(pbr->pointer);
 	PRINTF(" Boot Entry at: %08lX\n",bootaddr);
 	if (blk_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
 		if(verb)
@@ -203,7 +184,7 @@ found:
 	}
 	switch(pide->boot_media) {
 		case 0x00: /* no emulation */
-			info->size=le16_to_int(pide->sec_cnt)>>2;
+			info->size = get_unaligned_le16(pide->sec_cnt)>>2;
 			break;
 		case 0x01:	info->size=2400>>2; break; /* 1.2MByte Floppy */
 		case 0x02:	info->size=2880>>2; break; /* 1.44MByte Floppy */
@@ -211,7 +192,7 @@ found:
 		case 0x04:	info->size=2880>>2; break; /* dummy (HD Emulation) */
 		default:	info->size=0; break;
 	}
-	newblkaddr=le32_to_int(pide->rel_block_addr);
+	newblkaddr = get_unaligned_le32(pide->rel_block_addr);
 	info->start=newblkaddr;
 	PRINTF(" part %d found @ %lx size %lx\n",part_num,newblkaddr,info->size);
 	return 0;
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#11 lore raw

PATCH 4/14 part_iso: Drop the customer unaligned access functions

Quoted 6 lines · Simon Glass

One of these is causing a coverity warning. Drop these functions and use the standard U-Boot ones instead.

Reported-by Coverity (CID: 138499)

... but the subject says customer not custom.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/b0375b27/attachment.sig>
#12 lore raw

PATCH 4/14 part_iso: Drop the customer unaligned access functions

In reply to Simon Glass
Quoted 7 lines · Simon Glass

One of these is causing a coverity warning. Drop these functions and use the standard U-Boot ones instead.

Reported-by Coverity (CID: 138499)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/1c659e03/attachment.sig>
#13 lore raw

PATCH 5/14 part_efi: Drop the NULL check on dev_desc in part_print_efi()

In reply to Simon Glass

This cannot be NULL since part_print() calls this function and requires it to be non-NULL.

Reported-by Coverity (CID: 138498)

---

 disk/part_efi.c | 4 ----
 1 file changed, 4 deletions(-)
disk/part_efi.c +0 -4
index 77bdfcb..93a7e81 100644
@@ -184,10 +184,6 @@ void part_print_efi(struct blk_desc *dev_desc)
 	char uuid[37];
 	unsigned char *uuid_bin;
 
-	if (!dev_desc) {
-		printf("%s: Invalid Argument(s)\n", __func__);
-		return;
-	}
 	/* This function validates AND fills in the GPT header and PTE */
 	if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
 			 gpt_head, &gpt_pte) != 1) {
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#14 lore raw

PATCH 5/14 part_efi: Drop the NULL check on dev_desc in part_print_efi()

Quoted 5 lines · Simon Glass

This cannot be NULL since part_print() calls this function and requires it to be non-NULL.

Reported-by Coverity (CID: 138498)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/42efec48/attachment.sig>
#15 lore raw

PATCH 5/14 part_efi: Drop the NULL check on dev_desc in part_print_efi()

In reply to Simon Glass
Quoted 6 lines · Simon Glass

This cannot be NULL since part_print() calls this function and requires it to be non-NULL.

Reported-by Coverity (CID: 138498)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/169c1427/attachment.sig>
#16 lore raw

PATCH 6/14 part_efi: Drop NULL check in part_get_info_efi()

In reply to Simon Glass

This cannot be NULL since part_get_info() calls this function and requires it to be non-NULL.

Reported-by Coverity (CID: 138497)

---

 disk/part_efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
disk/part_efi.c +1 -1
index 93a7e81..fe308d7 100644
@@ -240,7 +240,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
 	gpt_entry *gpt_pte = NULL;
 
 	/* "part" argument must be at least 1 */
-	if (!dev_desc || !info || part < 1) {
+	if (part < 1) {
 		printf("%s: Invalid Argument(s)\n", __func__);
 		return -1;
 	}
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#17 lore raw

PATCH 6/14 part_efi: Drop NULL check in part_get_info_efi()

Quoted 6 lines · Simon Glass

This cannot be NULL since part_get_info() calls this function and requires it to be non-NULL.

Reported-by Coverity (CID: 138497)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/64ca3b37/attachment.sig>
#18 lore raw

PATCH 6/14 part_efi: Drop NULL check in part_get_info_efi()

In reply to Simon Glass
Quoted 7 lines · Simon Glass

This cannot be NULL since part_get_info() calls this function and requires it to be non-NULL.

Reported-by Coverity (CID: 138497)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/3c1c25ea/attachment.sig>
#19 lore raw

PATCH 7/14 mkimage: Close the file when unable to get its size

In reply to Simon Glass

There is a missing close() on the error path. Add it.

Reported-by Coverity (CID: 138496)

---

 tools/imagetool.c | 1 +
 1 file changed, 1 insertion(+)
tools/imagetool.c +1 -0
index 351211c..916ab96 100644
@@ -107,6 +107,7 @@ int imagetool_get_filesize(struct image_tool_params *params, const char *fname)
 	if (fstat(fd, &sbuf) < 0) {
 		fprintf(stderr, "%s: Can't stat %s: %s\n",
 			params->cmdname, fname, strerror(errno));
+		close(fd);
 		return -1;
 	}
 	close(fd);
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#20 lore raw

PATCH 7/14 mkimage: Close the file when unable to get its size

Quoted 4 lines · Simon Glass

There is a missing close() on the error path. Add it.

Reported-by Coverity (CID: 138496)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/32b26755/attachment.sig>
#21 lore raw

PATCH 7/14 mkimage: Close the file when unable to get its size

In reply to Simon Glass
Quoted 5 lines · Simon Glass

There is a missing close() on the error path. Add it.

Reported-by Coverity (CID: 138496)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/0e66ffe2/attachment.sig>
#22 lore raw

PATCH 8/14 mkimage: Add a missing free() to fit_import_data()

In reply to Simon Glass

The space allocated to fdt is not freed on error. Fix it.

Reported-by Coverity (CID: 138494)

---

 tools/fit_image.c | 1 +
 1 file changed, 1 insertion(+)
tools/fit_image.c +1 -0
index 8a93ea3..8d58370 100644
@@ -541,6 +541,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
 	ret = 0;
 
 err:
+	free(fdt);
 	close(fd);
 	return ret;
 }
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#23 lore raw

PATCH 8/14 mkimage: Add a missing free() to fit_import_data()

Quoted 5 lines · Simon Glass

The space allocated to fdt is not freed on error. Fix it.

Reported-by Coverity (CID: 138494)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/55e2e2f9/attachment.sig>
#24 lore raw

PATCH 8/14 mkimage: Add a missing free() to fit_import_data()

In reply to Simon Glass
Quoted 6 lines · Simon Glass

The space allocated to fdt is not freed on error. Fix it.

Reported-by Coverity (CID: 138494)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/1f92511b/attachment.sig>
#25 lore raw

PATCH 9/14 mkimage: Fix error path in fit_extract_data()

In reply to Simon Glass

The 'fdt' variable is not unmapped in all error cases. Fix this.

Reported-by Coverity (CID: 138493)

---

 tools/fit_image.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
tools/fit_image.c +7 -4
index 8d58370..bfb43b2 100644
@@ -385,7 +385,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 	buf = malloc(fit_size);
 	if (!buf) {
 		ret = -ENOMEM;
-		goto err;
+		goto err_munmap;
 	}
 	buf_ptr = 0;
 
@@ -393,7 +393,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 	if (images < 0) {
 		debug("%s: Cannot find /images node: %d\n", __func__, images);
 		ret = -EINVAL;
-		goto err;
+		goto err_munmap;
 	}
 
 	for (node = fdt_first_subnode(fdt, images);
@@ -411,7 +411,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 		ret = fdt_delprop(fdt, node, "data");
 		if (ret) {
 			ret = -EPERM;
-			goto err;
+			goto err_munmap;
 		}
 		fdt_setprop_u32(fdt, node, "data-offset", buf_ptr);
 		fdt_setprop_u32(fdt, node, "data-size", len);
@@ -446,8 +446,11 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 		ret = -EIO;
 		goto err;
 	}
-	ret = 0;
+	close(fd);
+	return 0;
 
+err_munmap:
+	munmap(fdt, sbuf.st_size);
 err:
 	close(fd);
 	return ret;
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#26 lore raw

PATCH 9/14 mkimage: Fix error path in fit_extract_data()

Quoted 5 lines · Simon Glass

The 'fdt' variable is not unmapped in all error cases. Fix this.

Reported-by Coverity (CID: 138493)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/dc884e3d/attachment.sig>
#27 lore raw

PATCH 9/14 mkimage: Fix error path in fit_extract_data()

In reply to Simon Glass
Quoted 6 lines · Simon Glass

The 'fdt' variable is not unmapped in all error cases. Fix this.

Reported-by Coverity (CID: 138493)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/bf94f40d/attachment.sig>
#28 lore raw

PATCH 10/14 mkimage: Fix missing free() in fit_extract_data()

In reply to Simon Glass

The 'buf' variable is not freed. Fix it.

Reported-by Coverity (CID: 138492)

---

 tools/fit_image.c | 2 ++
 1 file changed, 2 insertions(+)
tools/fit_image.c +2 -0
index bfb43b2..e628212 100644
@@ -452,6 +452,8 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 err_munmap:
 	munmap(fdt, sbuf.st_size);
 err:
+	if (buf)
+		free(buf);
 	close(fd);
 	return ret;
 }
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#29 lore raw

PATCH 10/14 mkimage: Fix missing free() in fit_extract_data()

Quoted 4 lines · Simon Glass

The 'buf' variable is not freed. Fix it.

Reported-by Coverity (CID: 138492)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/f9bf4e36/attachment.sig>
#30 lore raw

PATCH 10/14 mkimage: Fix missing free() in fit_extract_data()

In reply to Simon Glass
Quoted 5 lines · Simon Glass

The 'buf' variable is not freed. Fix it.

Reported-by Coverity (CID: 138492)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/40db93b1/attachment.sig>
#31 lore raw

PATCH 11/14 mkimage: Fix missing free() and close() in fit_build()

In reply to Simon Glass

Make sure that both the error path and normal return free the buffer and close the file.

Reported-by Coverity (CID: 138491)

---

 tools/fit_image.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/fit_image.c +4 -1
index e628212..9d553d1 100644
@@ -329,7 +329,7 @@ static int fit_build(struct image_tool_params *params, const char *fname)
 	if (ret < 0) {
 		fprintf(stderr, "%s: Failed to build FIT image\n",
 			params->cmdname);
-		goto err;
+		goto err_buf;
 	}
 	size = ret;
 	fd = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
@@ -346,9 +346,12 @@ static int fit_build(struct image_tool_params *params, const char *fname)
 		goto err;
 	}
 	close(fd);
+	free(buf);
 
 	return 0;
 err:
+	close(fd);
+err_buf:
 	free(buf);
 	return -1;
 }
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#32 lore raw

PATCH 11/14 mkimage: Fix missing free() and close() in fit_build()

Quoted 5 lines · Simon Glass

Make sure that both the error path and normal return free the buffer and close the file.

Reported-by Coverity (CID: 138491)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/32435f7d/attachment.sig>
#33 lore raw

PATCH 11/14 mkimage: Fix missing free() and close() in fit_build()

In reply to Simon Glass
Quoted 6 lines · Simon Glass

Make sure that both the error path and normal return free the buffer and close the file.

Reported-by Coverity (CID: 138491)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/12ca32e2/attachment.sig>
#34 lore raw

PATCH 12/14 mkimage: Ensure file is closed in fdt_property_file()

In reply to Simon Glass

The file that is opened is not closed in all cases. Fix it.

Reported-by Coverity (CID: 138490)

---

 tools/fit_image.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/fit_image.c +2 -1
index 9d553d1..6e5c143 100644
@@ -123,13 +123,14 @@ static int fdt_property_file(struct image_tool_params *params,
 
 	ret = fdt_property_placeholder(fdt, "data", sbuf.st_size, &ptr);
 	if (ret)
-		return ret;
+		goto err;
 	ret = read(fd, ptr, sbuf.st_size);
 	if (ret != sbuf.st_size) {
 		fprintf(stderr, "%s: Can't read %s: %s\n",
 			params->cmdname, fname, strerror(errno));
 		goto err;
 	}
+	close(fd);
 
 	return 0;
 err:
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#35 lore raw

PATCH 12/14 mkimage: Ensure file is closed in fdt_property_file()

Quoted 4 lines · Simon Glass

The file that is opened is not closed in all cases. Fix it.

Reported-by Coverity (CID: 138490)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/6bf5a5dd/attachment.sig>
#36 lore raw

PATCH 12/14 mkimage: Ensure file is closed in fdt_property_file()

In reply to Simon Glass
Quoted 5 lines · Simon Glass

The file that is opened is not closed in all cases. Fix it.

Reported-by Coverity (CID: 138490)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/8099caa6/attachment.sig>
#37 lore raw

PATCH 13/14 mkimage: Don't close the file if it wasn't opened

In reply to Simon Glass

The error path for fit_import_data() is incorrect if the second open() call fails.

Reported-by Coverity (CID: 138489)

---

 tools/fit_image.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/fit_image.c +2 -2
index 6e5c143..ddefa72 100644
@@ -537,8 +537,8 @@ static int fit_import_data(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));
-		ret = -EIO;
-		goto err;
+		free(fdt);
+		return -EIO;
 	}
 	if (write(fd, fdt, new_size) != new_size) {
 		debug("%s: Failed to write external data to file %s\n",
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#38 lore raw

PATCH 13/14 mkimage: Don't close the file if it wasn't opened

Quoted 5 lines · Simon Glass

The error path for fit_import_data() is incorrect if the second open() call fails.

Reported-by Coverity (CID: 138489)
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/8a11333f/attachment.sig>
#39 lore raw

PATCH 13/14 mkimage: Don't close the file if it wasn't opened

In reply to Simon Glass
Quoted 6 lines · Simon Glass

The error path for fit_import_data() is incorrect if the second open() call fails.

Reported-by Coverity (CID: 138489)

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/93552d29/attachment.sig>
#40 lore raw

PATCH 14/14 usb: Correct return value in usb_stor_info()

In reply to Simon Glass

This should return 0 on success, not 1. Fix it.

---

 common/usb_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/usb_storage.c +1 -1
index 1472824..18fdf73 100644
@@ -193,7 +193,7 @@ int usb_stor_info(void)
 		return 1;
 	}
 
-	return 1;
+	return 0;
 }
 
 static unsigned int usb_get_max_lun(struct us_data *us)
Signature · 1 line
2.7.0.rc3.207.g0ac5344
#41 lore raw

PATCH 14/14 usb: Correct return value in usb_stor_info()

Quoted 3 lines · Simon Glass

This should return 0 on success, not 1. Fix it.

Yikes. Thanks for finding this.

Quoted 19 lines

---

 common/usb_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/usb_storage.c +1 -1
index 1472824..18fdf73 100644
@@ -193,7 +193,7 @@ int usb_stor_info(void)
 		return 1;
 	}
 
-	return 1;
+	return 0;
 }
 
 static unsigned int usb_get_max_lun(struct us_data *us)
Signature · 2 lines
Best regards,
Marek Vasut
#42 lore raw

PATCH 14/14 usb: Correct return value in usb_stor_info()

In reply to Simon Glass
Quoted 3 lines · Simon Glass

This should return 0 on success, not 1. Fix it.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/a9a612bd/attachment.sig>
#43 lore raw

PATCH 14/14 usb: Correct return value in usb_stor_info()

In reply to Simon Glass
Quoted 5 lines · Simon Glass

This should return 0 on success, not 1. Fix it.

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: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160322/03cf43d1/attachment.sig>