From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3gRY-0005x0-TM for qemu-devel@nongnu.org; Fri, 20 May 2016 05:10:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3gRS-00065O-SD for qemu-devel@nongnu.org; Fri, 20 May 2016 05:10:03 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35613) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3gRS-00065A-LR for qemu-devel@nongnu.org; Fri, 20 May 2016 05:09:58 -0400 Received: by mail-wm0-x243.google.com with SMTP id s63so12884708wme.2 for ; Fri, 20 May 2016 02:09:58 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 20 May 2016 11:09:54 +0200 Message-Id: <1463735394-25690-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] crypto: assert that qcrypto_hash_digest_len is in range List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: danpb@redhat.com 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. Signed-off-by: Paolo Bonzini --- crypto/hash.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crypto/hash.c b/crypto/hash.c index b90af34..2907bff 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]; } -- 2.5.5