diff options
| author | James Hilliard <[email protected]> | 2026-08-10 23:17:41 -0600 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-08-20 12:15:24 -0600 |
| commit | 6073c36b2c8d39afe3ecc789b281667a3ddebc70 (patch) | |
| tree | d078454bb6d1bd0c0fae7b6bb2d5e5fa06d5c39a | |
| parent | 24635824319bf0b49998c47d22cfb2a1a45aed10 (diff) | |
test: dm: hash: check digest size before memset
hash_algo_digest_size() returns -EINVAL for an invalid algorithm. The
test success provider passes that result directly to memset(), where it
is converted to a large size_t.
Return the error before touching the output buffer, and exercise the
invalid-algorithm path in the provider-selection test. This addresses
Coverity CIDs 652907 and 652908.
Fixes: 94b349bd902d ("crypto: hash: use DM providers from hash command")
Signed-off-by: James Hilliard <[email protected]>
| -rw-r--r-- | test/dm/hash.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/test/dm/hash.c b/test/dm/hash.c index fe949e33de5..6adf916dc77 100644 --- a/test/dm/hash.c +++ b/test/dm/hash.c @@ -31,8 +31,14 @@ static int hash_test_success(struct udevice *dev, enum HASH_ALGO algo, const void *ibuf, const uint32_t ilen, void *obuf, uint32_t chunk_sz) { + ssize_t digest_size; + success_calls++; - memset(obuf, 0x5a, hash_algo_digest_size(algo)); + digest_size = hash_algo_digest_size(algo); + if (digest_size < 0) + return digest_size; + + memset(obuf, 0x5a, digest_size); return 0; } @@ -124,6 +130,14 @@ static int dm_test_hash_provider_selection(struct unit_test_state *uts) for (int i = 0; i < sizeof(digest); i++) ut_asserteq(0x5a, digest[i]); + memset(digest, 0, sizeof(digest)); + ret = hash_digest_wd_lookup(HASH_ALGO_INVALID, "test", 4, digest, 4); + ut_asserteq(-EINVAL, ret); + ut_asserteq(2, unsupported_calls); + ut_asserteq(2, success_calls); + for (int i = 0; i < sizeof(digest); i++) + ut_asserteq(0, digest[i]); + ut_assertok(hash_test_unbind_all()); ut_assertok(hash_test_bind(DM_DRIVER_GET(hash_test_hard_error_drv), "hash-hard-error")); |
