From 80a36f60534d30b3252c3e613070ff1071e7f9a9 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 8 Aug 2022 08:20:09 +0200 Subject: 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 Link: https://lore.barebox.org/20220808062010.390394-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- common/machine_id.c | 5 +++++ 1 file changed, 5 insertions(+) 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; -- cgit v1.2.3