From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/3] common: machine_id: guard against digest algo being unavailable
Date: Mon, 8 Aug 2022 08:20:09 +0200 [thread overview]
Message-ID: <20220808062010.390394-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220808062010.390394-1-a.fatoum@pengutronix.de>
All callsites of digest_alloc(_by_algo) check for NULL pointer before
proceeding except for machine_id_set_globalvar(). Fix this to fail
more gracefully instead of the crash I ran into.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/machine_id.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/common/machine_id.c b/common/machine_id.c
index a530fdeb1da8..189e74bd6796 100644
--- a/common/machine_id.c
+++ b/common/machine_id.c
@@ -30,14 +30,15 @@ static int machine_id_set_globalvar(void)
unsigned char machine_id[SHA1_DIGEST_SIZE];
char hex_machine_id[MACHINE_ID_LENGTH];
char *env_machine_id;
- int ret;
+ int ret = -EOPNOTSUPP;
/* nothing to do if no hashable information provided */
if (!__machine_id_hashable)
return 0;
digest = digest_alloc_by_algo(HASH_ALGO_SHA1);
- ret = digest_init(digest);
+ if (digest)
+ ret = digest_init(digest);
if (ret)
goto out;
--
2.30.2
next prev parent reply other threads:[~2022-08-08 6:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-08 6:20 [PATCH master 1/3] common: machine_id: simplify early exit Ahmad Fatoum
2022-08-08 6:20 ` Ahmad Fatoum [this message]
2022-08-08 11:48 ` [PATCH master 2/3] common: machine_id: guard against digest algo being unavailable Sascha Hauer
2022-08-08 11:50 ` Ahmad Fatoum
2022-08-08 6:20 ` [PATCH master 3/3] crypto: restrict digest algos implemented in ARM assembly to 32-bit Ahmad Fatoum
2022-08-08 11:40 ` [PATCH master 1/3] common: machine_id: simplify early exit Sascha Hauer
2022-08-08 11:43 ` Ahmad Fatoum
2022-08-09 4:41 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220808062010.390394-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox