]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
tools: mkimage: Call fclose in error path
authorMichal Simek <michal.simek@xilinx.com>
Tue, 20 Dec 2016 08:54:18 +0000 (09:54 +0100)
committerMichal Simek <michal.simek@xilinx.com>
Wed, 11 Jan 2017 13:10:38 +0000 (14:10 +0100)
This patch is fixing missing fclose() calls
in error patch introduced by:
"tools: mkimage: Use fstat instead of stat to avoid malicious hacks"
(sha1: ebe0f53f48e8f9ecc823e533a85b05c13638c350)

Reported-by: Coverity (CID: 155064, 155065)
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
tools/zynqimage.c
tools/zynqmpimage.c

index b47132b02a60f4441bcf1205213da6a08324163f..021d2d3fc91f0ae515b160b33a56a8872fd5dda2 100644 (file)
@@ -239,11 +239,15 @@ static void zynqimage_parse_initparams(struct zynq_header *zynqhdr,
        }
 
        err = fstat(fileno(fp), &path_stat);
-       if (err)
+       if (err) {
+               fclose(fp);
                return;
+       }
 
-       if (!S_ISREG(path_stat.st_mode))
+       if (!S_ISREG(path_stat.st_mode)) {
+               fclose(fp);
                return;
+       }
 
        do {
                r = fscanf(fp, "%x %x", &reginit.address, &reginit.data);
index 8260e5dd1526db08f74f1d2dac66a0bf77cb40b5..ac094c609277e154276e366d8c3d0c87cae7a24f 100644 (file)
@@ -300,11 +300,15 @@ static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
        }
 
        err = fstat(fileno(fp), &path_stat);
-       if (err)
+       if (err) {
+               fclose(fp);
                return;
+       }
 
-       if (!S_ISREG(path_stat.st_mode))
+       if (!S_ISREG(path_stat.st_mode)) {
+               fclose(fp);
                return;
+       }
 
        do {
                r = fscanf(fp, "%x %x", &reginit.address, &reginit.data);