[PATCH master 2/3] common: machine_id: guard against digest algo being unavailable

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Aug 8 04:50:19 PDT 2022


On 08.08.22 13:48, Sascha Hauer wrote:
> On Mon, Aug 08, 2022 at 08:20:09AM +0200, Ahmad Fatoum wrote:
>> 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 at 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);
> 
> Had to read this twice to be sure it's correct. A plain
> 
> 	if (!digest) {
> 		ret = -EOPNOTSUPP;
> 		goto out;
> 	}
> 
> seems easier to follow.

Fine by me. Can you fixup or should I?

Cheers,
Ahmad

> 
> Sascha
> 
>> -	ret = digest_init(digest);
>> +	if (digest)
>> +		ret = digest_init(digest);
>>  	if (ret)
>>  		goto out;
>>  
>> -- 
>> 2.30.2
>>
>>
>>
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list