From patchwork Fri Sep 3 14:59:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 506540 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp1074491jai; Fri, 3 Sep 2021 08:01:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJtYrb1/s5AMGdQioo/jt/Jd0ehUKmV43ugg1l81ZIIDzIBOSb7jtQ7dX+ZqbYYFxl+tNM X-Received: by 2002:a67:c786:: with SMTP id t6mr3097995vsk.40.1630681279793; Fri, 03 Sep 2021 08:01:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630681279; cv=none; d=google.com; s=arc-20160816; b=x8V4YPV+i9eS3KRctAFGPqiGE7h7b7nVmxEwXUiLMGunur/qx0SSwb24lQzQvYqPH1 DFeiCVGxiq/8HScfj7xNgHdfV/wLmC9+UbJHgMJPcgUXOLiBr4bUhTpc4CqBASj7p0dJ izpuC2arl6GbHT0i570pMN0Dr5kGBJ25JKM9Qa/I1tX9tzIV6mRh5Myj9yXUGaqFPttL Unv2JcetFEfa0awoZXRnnS5yKKCu1eIZSQ2Gc431R/CKCyjUFf39yEHxFgjX/6OXlxg0 mCieun5C+ILpBNuF30S84KJL2qO/kHtPSuqt04D2QsyyBmRssN1nhQ/r7y3JoHK1TJay T3qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=eWIxMU12TOrgBs0giYNKVvqdRflVmfRfnBEVeqj3WTg=; b=GRj254flycJWfHRyY6EqdWb/UCKA+ZDN1tF7vs5L3SLcCwSyTEdUvYDydtq1a3x1pX ZxKlwo1q2FyTyyM3wK+seupiU94Zosi/QYvYylG4Xyi4lqmr59h+ufX6MN57T54hvIRR 37LQYoCQvznB/xMpAPBnyAd9yEapaIM5ZvxKQLRqJ07WMnSg8RM3y/NCHKTCMkg1B7/x vElngweEygoLNFatkarJjHh7f3QxU9gQF+cbLpU/hh9rj0BETAfDwyBqrscsk2vgZKv4 BJaciRRMjS0KhrO6qDEC6txxZiN80IUS7bLKwXibac4Awz819mYgqHhdWjLDQLzxD9zn AMvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QdwQzLyY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r20si2676246vsl.314.2021.09.03.08.01.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Sep 2021 08:01:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QdwQzLyY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMAgx-0001Cu-56 for patch@linaro.org; Fri, 03 Sep 2021 11:01:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMAfV-0001Cd-2t for qemu-devel@nongnu.org; Fri, 03 Sep 2021 10:59:49 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:35667) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mMAfT-0002pg-AC for qemu-devel@nongnu.org; Fri, 03 Sep 2021 10:59:48 -0400 Received: by mail-wr1-x42e.google.com with SMTP id i6so8648854wrv.2 for ; Fri, 03 Sep 2021 07:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eWIxMU12TOrgBs0giYNKVvqdRflVmfRfnBEVeqj3WTg=; b=QdwQzLyYzsWY3v5d0egPyG7MGbcb3hGgz0eRfkAFLEdK3585v1pGtwsZNYmraM/05k pSl/k5SIKSuhSYnc5t17p1SmGxOSc1RkgP4+8CAPOJaKINrJ3vjJ+YQ5Obgc5UgsoKNS 73LP+Et71LzcP6mn077mLkYbn6mwHBq7WEwYuwYAErX05A8PKapjIv0jHBWAZkvhEtRr kaRqPozGGRVNjMaPoRDB5XXj4WIMiB4hARR2CDZ9JQgCpVSvAG8v93BYE6XFvjP5IhSp 22b6Omj2OBBgtQpdCB88H+bRxQnoG50cr5IwEfC6eJg38HAif5jPbWrBfbqlN/rkcjE0 6LSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eWIxMU12TOrgBs0giYNKVvqdRflVmfRfnBEVeqj3WTg=; b=Y1RRuCzHTn9rHYpZ+uXbo2v1P8lD+XxJPCh4Bkae5GUO04/KpSAO7dwIcW+OnauQkQ //paPqPgX9CIgR3wCYzYgRfbWW91hf1bA94hvtsKPXneg4W+PUIG+g0/1wAepFtVYDQK 1GQPveNdHBmgScNiENs2ZCsJQ/yAS//sgWAi51W2SxclvDtEkACZ1pndZUemnt0VbmEQ +DPOwk9+PIYzm8EPz+ofdfztwf5+XleyIDbwPxQT9y21FAqf7fqNzww+VBRz65YKt66t gD1cEN6A22hL4FpKqGQwXDmOQlR8eXLoRK012PTmTcLKjUh9uT+VM+kCookEEzKBOdn6 NJLw== X-Gm-Message-State: AOAM530iapJKBC538uHtFxQ8mELUca93QD2vSFQQXO+IW9w8c/p3P9zm jR83UbW+9Fto03JdQZcK5pSBkA== X-Received: by 2002:adf:f84d:: with SMTP id d13mr4797801wrq.292.1630681185032; Fri, 03 Sep 2021 07:59:45 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x9sm4296548wmi.30.2021.09.03.07.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 07:59:44 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6AD0B1FF96; Fri, 3 Sep 2021 15:59:43 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH] accel/tcg: assert insn_idx will always be valid before plugin_inject_cb Date: Fri, 3 Sep 2021 15:59:38 +0100 Message-Id: <20210903145938.1321571-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: peter.maydell@linaro.org, Richard Henderson , =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Coverity doesn't know enough about how we have arranged our plugin TCG ops to know we will always have incremented insn_idx before injecting the callback. Let us assert it for the benefit of Coverity and protect ourselves from accidentally breaking the assumption and triggering harder to grok errors deeper in the code if we attempt a negative indexed array lookup. Fixes: Coverity 1459509 Signed-off-by: Alex Bennée --- accel/tcg/plugin-gen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.30.2 diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 88e25c6df9..b38aa1bb36 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -820,10 +820,9 @@ static void pr_ops(void) static void plugin_gen_inject(const struct qemu_plugin_tb *plugin_tb) { TCGOp *op; - int insn_idx; + int insn_idx = -1; pr_ops(); - insn_idx = -1; QSIMPLEQ_FOREACH(op, &tcg_ctx->plugin_ops, plugin_link) { enum plugin_gen_from from = op->args[0]; enum plugin_gen_cb type = op->args[1]; @@ -834,6 +833,7 @@ static void plugin_gen_inject(const struct qemu_plugin_tb *plugin_tb) type == PLUGIN_GEN_ENABLE_MEM_HELPER) { insn_idx++; } + g_assert(from == PLUGIN_GEN_FROM_TB || insn_idx >= 0); plugin_inject_cb(plugin_tb, op, insn_idx); } pr_ops();