From patchwork Fri May 20 09:09:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9129005 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 ECDA16048B for ; Fri, 20 May 2016 09:10:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E004C25D91 for ; Fri, 20 May 2016 09:10:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4B3D2796F; Fri, 20 May 2016 09:10:21 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 4742B25D91 for ; Fri, 20 May 2016 09:10:20 +0000 (UTC) Received: from localhost ([::1]:53906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3gRn-0005yM-II for patchwork-qemu-devel@patchwork.kernel.org; Fri, 20 May 2016 05:10:19 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=vdsaby3LO/zA7b4vAR3e8KcRUofGTBBqw3tTwGC5r0I=; b=uhHrCYUXplWDXVpj1+CzDNxmrlarkBMZZyapexDUsntoEuyVb3/W+Z6TKou8BtD52B N7lPlX93Q2utjjNDnIzSsxME3W/PJthpU6swfxSrrbsQCcLR5xdmtgBq2sTmqqUhtLW1 qU9KFnZjWGnj7Lmd88K20xuJNem/TFj2UV9mx/x92q8agivs0uaT3gM3dELreZHajyYx 1BKH/hBATLma/2c7QdfZ/b0JXkQIGKqGZWkgWUy/GNNjTiH5axToyAy15sZviW/ZskSh CxBknlykielNx+byq/Bs1hfjrYGeQMwRVPVbPyoEJFYBonX3I9yzp6HQDGeNDtscM54y ex5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=vdsaby3LO/zA7b4vAR3e8KcRUofGTBBqw3tTwGC5r0I=; b=TYQ0h1zAbDZQm3r9Gr/TwQHyRL7YR/gh11kSjURnXQsZz8u2BSsHx11kX3RI06TrvU bWMRbX3WiL5FUyqoJjBN0vAUx3qnwwg1KXZeynmO1we1gVoW4KeYmYOiNTPWk3IdKj51 h7E+0YvXmv/IrEPTCUsjbhwP3e/MEletAh3Q866bK0ay288rT/COK2IOrYUdPxu44tQC F00gqc1DfqnBII8QKmaRNmdZEpHmdYt2yt0URah7zfjrApvsrhWc0FIu1efX/PU4QjeN UZrdB2UwsV7C52P6hpKLCUMRuhuzAIg/Q7Y/aBVL10iOpRthR7HgozIQrVz8MbI1dbSV CRgA== X-Gm-Message-State: AOPr4FXecJSabr8FfvVH0zWPA1xm1pSapA9nfDBrftOedjhVjK7dzwOBgv6AAziOfPRdZA== X-Received: by 10.194.107.6 with SMTP id gy6mr2155882wjb.20.1463735397791; Fri, 20 May 2016 02:09:57 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-252-58.clienti.tiscali.it. [78.12.252.58]) by smtp.gmail.com with ESMTPSA id q76sm3576893wmd.6.2016.05.20.02.09.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 May 2016 02:09:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 20 May 2016 11:09:54 +0200 Message-Id: <1463735394-25690-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH] crypto: assert that qcrypto_hash_digest_len is in range 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: danpb@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Eric Blake --- 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]; }