]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
kwbimage: check fopen() return value
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 17 Aug 2021 05:03:20 +0000 (07:03 +0200)
committerStefan Roese <sr@denx.de>
Wed, 1 Sep 2021 06:09:24 +0000 (08:09 +0200)
Always check the return value of fopen().

This resolves Coverity CID 338491:
Null pointer dereferences (NULL_RETURNS)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Stefan Roese <sr@denx.de>
Reviewed-by: Pali Rohár <pali@kernel.org>
tools/kwbimage.c

index 9fab04ce88d6b214763e13627c90aa7c33e05e73..b2694888d965698a8b861e7a0dcf51729b4590e7 100644 (file)
@@ -832,6 +832,12 @@ static int kwb_dump_fuse_cmds(struct secure_hdr_v1 *sec_hdr)
        if (!strcmp(e->name, "a38x")) {
                FILE *out = fopen("kwb_fuses_a38x.txt", "w+");
 
+               if (!out) {
+                       fprintf(stderr, "Couldn't open eFuse settings: '%s': %s\n",
+                               "kwb_fuses_a38x.txt", strerror(errno));
+                       return -ENOENT;
+               }
+
                kwb_dump_fuse_cmds_38x(out, sec_hdr);
                fclose(out);
                goto done;
@@ -1060,6 +1066,11 @@ int export_pub_kak_hash(RSA *kak, struct secure_hdr_v1 *secure_hdr)
        int res;
 
        hashf = fopen("pub_kak_hash.txt", "w");
+       if (!hashf) {
+               fprintf(stderr, "Couldn't open hash file: '%s': %s\n",
+                       "pub_kak_hash.txt", strerror(errno));
+               return 1;
+       }
 
        res = kwb_export_pubkey(kak, &secure_hdr->kak, hashf, "KAK");