mirror of https://gitee.com/openkylin/qemu.git
crypto: assert that qcrypto_hash_digest_len is in range
Otherwise unintended results could happen. For example, Coverity reports a division by zero in qcrypto_afsplit_hash. While this cannot really happen, it shows that the contract of qcrypto_hash_digest_len can be improved. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
e7ed11f083
commit
b35c1f3361
|
@ -36,9 +36,7 @@ static size_t qcrypto_hash_alg_size[QCRYPTO_HASH_ALG__MAX] = {
|
|||
|
||||
size_t qcrypto_hash_digest_len(QCryptoHashAlgorithm alg)
|
||||
{
|
||||
if (alg >= G_N_ELEMENTS(qcrypto_hash_alg_size)) {
|
||||
return 0;
|
||||
}
|
||||
assert(alg < G_N_ELEMENTS(qcrypto_hash_alg_size));
|
||||
return qcrypto_hash_alg_size[alg];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue