]> git.sur5r.net Git - u-boot/commitdiff
tools: imximage: check return value when open the plugin file
authorPeng Fan <peng.fan@nxp.com>
Fri, 4 Nov 2016 02:33:15 +0000 (10:33 +0800)
committerTom Rini <trini@konsulko.com>
Sat, 5 Nov 2016 11:27:44 +0000 (07:27 -0400)
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>
tools/imximage.c

index 615a64e727f0b10e5152ab6685292f9922c0f164..c9e42ec5cab54e18a60af4c44c74b7e9c72e8b06 100644 (file)
@@ -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,