* [PATCH 1/1] kwbimage: check fopen() return value
@ 2021-08-17 5:03 Heinrich Schuchardt
2021-08-17 6:46 ` Stefan Roese
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Heinrich Schuchardt @ 2021-08-17 5:03 UTC (permalink / raw)
To: Tom Rini
Cc: Marek Behún, Pali Rohár, Stefan Roese, Chris Packham,
u-boot, Heinrich Schuchardt
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>
---
tools/kwbimage.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 00cb338d64..2a10df773b 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -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");
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] kwbimage: check fopen() return value
2021-08-17 5:03 [PATCH 1/1] kwbimage: check fopen() return value Heinrich Schuchardt
@ 2021-08-17 6:46 ` Stefan Roese
2021-08-17 8:31 ` Pali Rohár
2021-09-01 9:14 ` Stefan Roese
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Roese @ 2021-08-17 6:46 UTC (permalink / raw)
To: Heinrich Schuchardt, Tom Rini
Cc: Marek Behún, Pali Rohár, Chris Packham, u-boot
On 17.08.21 07:03, Heinrich Schuchardt wrote:
> 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>
Thanks,
Stefan
> ---
> tools/kwbimage.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 00cb338d64..2a10df773b 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -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");
>
> --
> 2.30.2
>
Viele Grüße,
Stefan
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] kwbimage: check fopen() return value
2021-08-17 5:03 [PATCH 1/1] kwbimage: check fopen() return value Heinrich Schuchardt
2021-08-17 6:46 ` Stefan Roese
@ 2021-08-17 8:31 ` Pali Rohár
2021-09-01 9:14 ` Stefan Roese
2 siblings, 0 replies; 4+ messages in thread
From: Pali Rohár @ 2021-08-17 8:31 UTC (permalink / raw)
To: Heinrich Schuchardt
Cc: Tom Rini, Marek Behún, Stefan Roese, Chris Packham, u-boot
On Tuesday 17 August 2021 07:03:20 Heinrich Schuchardt wrote:
> 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: Pali Rohár <pali@kernel.org>
> ---
> tools/kwbimage.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 00cb338d64..2a10df773b 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -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");
>
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] kwbimage: check fopen() return value
2021-08-17 5:03 [PATCH 1/1] kwbimage: check fopen() return value Heinrich Schuchardt
2021-08-17 6:46 ` Stefan Roese
2021-08-17 8:31 ` Pali Rohár
@ 2021-09-01 9:14 ` Stefan Roese
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Roese @ 2021-09-01 9:14 UTC (permalink / raw)
To: Heinrich Schuchardt, Tom Rini
Cc: Marek Behún, Pali Rohár, Chris Packham, u-boot
On 17.08.21 07:03, Heinrich Schuchardt wrote:
> 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>
Applied to u-boot-marvell/master
Thanks,
Stefan
> ---
> tools/kwbimage.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 00cb338d64..2a10df773b 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -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");
>
> --
> 2.30.2
>
Viele Grüße,
Stefan
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-01 9:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17 5:03 [PATCH 1/1] kwbimage: check fopen() return value Heinrich Schuchardt
2021-08-17 6:46 ` Stefan Roese
2021-08-17 8:31 ` Pali Rohár
2021-09-01 9:14 ` Stefan Roese
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.