lib: parameter check in hash_calculate

If hash_calculate is invoked with region_count = 0, it will try to hash
INT_MAX regions. We should check this parameter.

* Avoid a comparison with different signedness.
* Check that region_count is at least 1.
* Avoid a superfluous assignment.

Fixes: b37b46f042 ("rsa: Use checksum algorithms from struct hash_algo")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Heinrich Schuchardt 2023-08-22 11:10:20 +02:00
parent e508b93002
commit eb48efce26

View file

@ -23,8 +23,10 @@ int hash_calculate(const char *name,
struct hash_algo *algo; struct hash_algo *algo;
int ret = 0; int ret = 0;
void *ctx; void *ctx;
uint32_t i; int i;
i = 0;
if (region_count < 1)
return -EINVAL;
ret = hash_progressive_lookup_algo(name, &algo); ret = hash_progressive_lookup_algo(name, &algo);
if (ret) if (ret)