]> git.proxmox.com Git - mirror_qemu.git/commitdiff
crypto: assert cipher algorithm is always valid
authorPrasad J Pandit <pjp@fedoraproject.org>
Mon, 20 Feb 2017 11:23:07 +0000 (16:53 +0530)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 27 Feb 2017 13:37:14 +0000 (13:37 +0000)
Crypto routines 'qcrypto_cipher_get_block_len' and
'qcrypto_cipher_get_key_len' return non-zero cipher block and key
lengths from static arrays 'alg_block_len[]' and 'alg_key_len[]'
respectively. Returning 'zero(0)' value from either of them would
likely lead to an error condition.

Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
crypto/cipher.c

index 9ecaff702b7ae0fa6af9a090ca331048790b2b1a..5a9648942f84185ec796478fe4e837d258ee93de 100644 (file)
@@ -63,18 +63,14 @@ static bool mode_need_iv[QCRYPTO_CIPHER_MODE__MAX] = {
 
 size_t qcrypto_cipher_get_block_len(QCryptoCipherAlgorithm alg)
 {
-    if (alg >= G_N_ELEMENTS(alg_key_len)) {
-        return 0;
-    }
+    assert(alg < G_N_ELEMENTS(alg_key_len));
     return alg_block_len[alg];
 }
 
 
 size_t qcrypto_cipher_get_key_len(QCryptoCipherAlgorithm alg)
 {
-    if (alg >= G_N_ELEMENTS(alg_key_len)) {
-        return 0;
-    }
+    assert(alg < G_N_ELEMENTS(alg_key_len));
     return alg_key_len[alg];
 }