From patchwork Fri Jun 21 01:42:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 11008395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F55513AF for ; Fri, 21 Jun 2019 02:09:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D5BA28908 for ; Fri, 21 Jun 2019 02:09:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81BEA2893F; Fri, 21 Jun 2019 02:09:07 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 329AB28908 for ; Fri, 21 Jun 2019 02:09:07 +0000 (UTC) Received: from localhost ([::1]:54154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8zC-000068-FT for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Jun 2019 22:09:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41124) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8a4-0006bX-5F for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1he8a2-0006b9-88 for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:07 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:42904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1he8Zz-0006PG-UB for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:05 -0400 Received: by mail-wr1-x42c.google.com with SMTP id x17so4853678wrl.9 for ; Thu, 20 Jun 2019 18:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H+GIX/ew7P3W1KtFZyQEoH7Aekz0PvrQKasKssVk2dE=; b=UQqN+g+rGVJFiDtwxSCJ/I5UCMAg0iWU98+JJfS37weqiSaGUgVF3gpEtGRus4Nc3g 4IZ+1b+VwZYdn8m0C7kP78X5CAGub149gjaqJ32uH3jFTrL4ewu0iH3vVn+N5anj468V eWOAST9kUjg7n7YLi7zam6dAncsprTI4HShQCAyoYCIIO37xYMT92TgzvAi1mEcohbeI esNePagtKBzZ7fj0GJ6HUnWpHeOrCoGCfvvRIjpcESCkwNYVfF3qDFEhAiMjjq8+9cwH jlh0i1tOG4Ihb9zpa2wHgOZuK6vteIHogvWBLEq1qu8MsuWcKyfkB+4NGowBeMMUX1rY v2/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=H+GIX/ew7P3W1KtFZyQEoH7Aekz0PvrQKasKssVk2dE=; b=CrOU1xafyi5MSx+gzGO0tFKKn3l48/tiw1thG1vgqgR3T5DlGVxtwav1yZcXTs8FQ3 3l5Bd5xaFubZOEIeTjAwTd/SoGYLkkkmC6gxk9e2TamohNrtXKDiL8xMmmvGJCjARv+N 3iYKz48UkUBI2IAly9EesJaaGOB4pVRdZAWawkFauUOF3UJDLV/RFW+A8CMGiM2rjD/R 1QolWOPtJlrUUwf+w2DEyRhhJRmH0bg7MgCyM2fhbTBmwstdtal30TK8ktgKOf8M7O58 7Wk6KDSgV/GhMdHxHaN2sixEIcYKatAhNz0wE7GTEdAe/yekDRcEw+IFlDtbWT+/eI5l 9FIQ== X-Gm-Message-State: APjAAAUpN93PbWkFQjY1hBF3taZY+D0z2u5nlWrI28+dM5zX4ALPD2rd sN51ayce6I+5o3XNL8vn6WYO/eC5 X-Google-Smtp-Source: APXvYqzPFgdsHu8f1uF3j80J4QwlBMQwQ5bnufYUnTv2iaOZhEKcnSON0bKfMhf1KjJrbi+W1F4n1A== X-Received: by 2002:adf:9bd3:: with SMTP id e19mr15643087wrc.38.1561081375774; Thu, 20 Jun 2019 18:42:55 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d1sm1123125wru.41.2019.06.20.18.42.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 18:42:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 03:42:28 +0200 Message-Id: <1561081350-3723-24-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> References: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c Subject: [Qemu-devel] [PULL 23/25] sd: Fix out-of-bounds assertions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lidong Chen Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Lidong Chen Due to an off-by-one error, the assert statements allow an out-of-bound array access. This doesn't happen in practice, but the static analyzer notices. Signed-off-by: Lidong Chen Reviewed-by: Liam Merwick Reviewed-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Li Qiang Reviewed-by: Darren Kenny Message-Id: <6b19cb7359a10a6bedc3ea0fce22fed3ef93c102.1560806687.git.lidong.chen@oracle.com> Signed-off-by: Paolo Bonzini --- hw/sd/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 60500ec..917195a6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -145,7 +145,7 @@ static const char *sd_state_name(enum SDCardStates state) if (state == sd_inactive_state) { return "inactive"; } - assert(state <= ARRAY_SIZE(state_name)); + assert(state < ARRAY_SIZE(state_name)); return state_name[state]; } @@ -166,7 +166,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp) if (rsp == sd_r1b) { rsp = sd_r1; } - assert(rsp <= ARRAY_SIZE(response_name)); + assert(rsp < ARRAY_SIZE(response_name)); return response_name[rsp]; }