]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: mkimage: Call fclose in error path
authorMichal Simek <michal.simek@xilinx.com>
Tue, 20 Dec 2016 08:58:31 +0000 (09:58 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 27 Dec 2016 16:24:16 +0000 (11:24 -0500)
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>
Reviewed-by: Simon Glass <sjg@chromium.org>
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 60d8ed23b4a1ca1eda75a261e391578e931e958e..0c9a3daddd6a9a6e14586fe1092f1203b151072e 100644 (file)
@@ -251,11 +251,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);