diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-08-08 08:20:09 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-08-09 06:40:35 +0200 |
commit | 80a36f60534d30b3252c3e613070ff1071e7f9a9 (patch) | |
tree | 371f69b9a57dfbd441458bc0df471f58543e9889 | |
parent | b5a386522d9cc72be551706b7ff9d84f87b15f7b (diff) | |
download | barebox-80a36f60534d30b3252c3e613070ff1071e7f9a9.tar.gz barebox-80a36f60534d30b3252c3e613070ff1071e7f9a9.tar.xz |
common: machine_id: guard against digest algo being unavailable
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>
Link: https://lore.barebox.org/20220808062010.390394-2-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/machine_id.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/common/machine_id.c b/common/machine_id.c index a530fdeb1d..8c273b9349 100644 --- a/common/machine_id.c +++ b/common/machine_id.c @@ -37,6 +37,11 @@ static int machine_id_set_globalvar(void) return 0; digest = digest_alloc_by_algo(HASH_ALGO_SHA1); + if (!digest) { + ret = -EOPNOTSUPP; + goto out; + } + ret = digest_init(digest); if (ret) goto out; |