aboutsummaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2016-05-20 11:09:54 +0200
committerDaniel P. Berrange <berrange@redhat.com>2016-06-13 12:41:17 +0100
commitb35c1f3361ebf6ec9ea5022903af4b559bff6063 (patch)
tree74a8cc5b6b93c0d682876e98ff8240f7c3d34ddc /crypto
parente7ed11f083015bf34a121cfff31540cf9c2bae23 (diff)
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>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/hash.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/crypto/hash.c b/crypto/hash.c
index b90af3495a..2907bffd2e 100644
--- a/crypto/hash.c
+++ b/crypto/hash.c
@@ -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];
}