From patchwork Mon Feb 20 11:23:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9582587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EDA2B6042F for ; Mon, 20 Feb 2017 11:23:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDA5D287FA for ; Mon, 20 Feb 2017 11:23:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFE3F28864; Mon, 20 Feb 2017 11:23:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 53EC5287FA for ; Mon, 20 Feb 2017 11:23:46 +0000 (UTC) Received: from localhost ([::1]:37551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfm4H-0008I1-6G for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Feb 2017 06:23:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfm3n-0008Ek-SJ for qemu-devel@nongnu.org; Mon, 20 Feb 2017 06:23:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cfm3m-0005pJ-S7 for qemu-devel@nongnu.org; Mon, 20 Feb 2017 06:23:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48200) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cfm3m-0005p3-M6 for qemu-devel@nongnu.org; Mon, 20 Feb 2017 06:23:14 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D80BDC00AFCF; Mon, 20 Feb 2017 11:23:14 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-64.phx2.redhat.com [10.3.116.64]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1KBNAJg017559 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 20 Feb 2017 06:23:12 -0500 From: P J P To: Qemu Developers Date: Mon, 20 Feb 2017 16:53:07 +0530 Message-Id: <20170220112307.31695-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 20 Feb 2017 11:23:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] crypto: assert cipher algorithm is always valid X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Prasad J Pandit Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit 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 Reviewed-by: Daniel P. Berrange --- crypto/cipher.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crypto/cipher.c b/crypto/cipher.c index 9ecaff7..5a96489 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c @@ -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]; }