public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] tools: imximage: check return value when open the plugin file
@ 2016-11-04  2:33 Peng Fan
  2016-11-04 11:21 ` Tom Rini
  2016-11-07  1:15 ` [U-Boot] " Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Peng Fan @ 2016-11-04  2:33 UTC (permalink / raw)
  To: u-boot

Check return value when open the plugin file.

Coverity report:
** CID 153926:  Error handling issues  (NEGATIVE_RETURNS)
/tools/imximage.c: 542 in copy_plugin_code()

   ifd = open(plugin_file, O_RDONLY|O_BINARY);
>>>  CID 153926:  Error handling issues  (NEGATIVE_RETURNS)
>>> "ifd" is passed to a parameter that cannot be negative.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Tom Rini <trini@konsulko.com>
---
 tools/imximage.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/imximage.c b/tools/imximage.c
index 615a64e..c9e42ec 100644
--- a/tools/imximage.c
+++ b/tools/imximage.c
@@ -533,12 +533,19 @@ static void print_hdr_v2(struct imx_header *imx_hdr)
 
 static void copy_plugin_code(struct imx_header *imxhdr, char *plugin_file)
 {
-	int ifd = -1;
+	int ifd;
 	struct stat sbuf;
 	char *plugin_buf = imxhdr->header.hdr_v2.data.plugin_code;
 	char *ptr;
 
 	ifd = open(plugin_file, O_RDONLY|O_BINARY);
+	if (ifd < 0) {
+		fprintf(stderr, "Can't open %s: %s\n",
+			plugin_file,
+			strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+
 	if (fstat(ifd, &sbuf) < 0) {
 		fprintf(stderr, "Can't stat %s: %s\n",
 			plugin_file,
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] tools: imximage: check return value when open the plugin file
  2016-11-04  2:33 [U-Boot] [PATCH] tools: imximage: check return value when open the plugin file Peng Fan
@ 2016-11-04 11:21 ` Tom Rini
  2016-11-07  1:15 ` [U-Boot] " Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2016-11-04 11:21 UTC (permalink / raw)
  To: u-boot

On Fri, Nov 04, 2016 at 10:33:15AM +0800, Peng Fan wrote:

> Check return value when open the plugin file.
> 
> Coverity report:
> ** CID 153926:  Error handling issues  (NEGATIVE_RETURNS)
> /tools/imximage.c: 542 in copy_plugin_code()
> 
>    ifd = open(plugin_file, O_RDONLY|O_BINARY);
> >>>  CID 153926:  Error handling issues  (NEGATIVE_RETURNS)
> >>> "ifd" is passed to a parameter that cannot be negative.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Tom Rini <trini@konsulko.com>

Reported-by: Coverity (CID: 153926)
Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161104/d41a3a33/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] tools: imximage: check return value when open the plugin file
  2016-11-04  2:33 [U-Boot] [PATCH] tools: imximage: check return value when open the plugin file Peng Fan
  2016-11-04 11:21 ` Tom Rini
@ 2016-11-07  1:15 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2016-11-07  1:15 UTC (permalink / raw)
  To: u-boot

On Fri, Nov 04, 2016 at 10:33:15AM +0800, Peng Fan wrote:

> Check return value when open the plugin file.
> 
> Coverity report:
> ** CID 153926:  Error handling issues  (NEGATIVE_RETURNS)
> /tools/imximage.c: 542 in copy_plugin_code()
> 
>    ifd = open(plugin_file, O_RDONLY|O_BINARY);
> >>>  CID 153926:  Error handling issues  (NEGATIVE_RETURNS)
> >>> "ifd" is passed to a parameter that cannot be negative.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Tom Rini <trini@konsulko.com>
> Reported-by: Coverity (CID: 153926)
> Reviewed-by: Tom Rini <trini@konsulko.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161106/61e08b79/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-07  1:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-04  2:33 [U-Boot] [PATCH] tools: imximage: check return value when open the plugin file Peng Fan
2016-11-04 11:21 ` Tom Rini
2016-11-07  1:15 ` [U-Boot] " Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox