From nobody Thu Nov 6 08:32:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497524241934931.7198883697781; Thu, 15 Jun 2017 03:57:21 -0700 (PDT) Received: from localhost ([::1]:53141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLSSm-0002wm-4l for importer@patchew.org; Thu, 15 Jun 2017 06:57:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLSOv-0008Az-6L for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLSOu-0007VL-Ca for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:21 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:34337) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dLSOu-0007V4-6I for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:20 -0400 Received: by mail-wr0-x241.google.com with SMTP id y25so545332wrd.1 for ; Thu, 15 Jun 2017 03:53:20 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id f21sm3258597wra.5.2017.06.15.03.53.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 03:53:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=0T9xITs789Uum+6iPBjrDiAlzxP0JNrmTz643oj/1K8=; b=fOIFh8fH/9UUWBRqAk80Nz9KGb0aom/tViC7Sj0ZkD7bQQq73Nf055PI968/sKuGNX vBBPe4BC1Rj0i2/rMRY/yGXFyxAOp/wufTjkLEpbMXLcr4/frl8LEeVwg6ytClHfyMba rLyeVZSSNlGleZOAliCRJOMsT5nChmP8dRIarZBRsZxORoN/nVpwir0d1qIc8k7K/xcF ehDD74os/mYyVqabncfKkJHZ/M2R7Xxvt5hDZ7kgyNuKLIVC63cXHitEmtgbdfJvARn1 Nv5Fd0fzxVpp5s5DKJiH8e0GLGk+izxoAwmCrO23WHirhfDAmVDJaYrXEYf00k5050dk WlGA== 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:subject:date:message-id :in-reply-to:references; bh=0T9xITs789Uum+6iPBjrDiAlzxP0JNrmTz643oj/1K8=; b=egz+A8hI5OJ3NPztTb1vWIe1PDpNIb99g5DGIDT+/6rpL4mW5zMyUVkeIzO9LWnn3X i5bxcymlDJQUBp3rmU2ZbNBQaZs6j3eTtNxqIx3HrUAbenXmhykz4cq3dmaN1mCn4Mdu s+HCs0/6MvZkXbZasASfyFSH2l30RZV72MXofhmfNzNGZEtp0uYPpG3ztly1MU/1VdVG vs6Ybtt534WilDOlwNKa06wO5/7GokRm09RN8zDcSmPXBEC54eO90y7FllZCCf4jh2kX 6ZJBSf2hBNqCPcrvey9/bwODsALqfVAjVBh09M77lPMNoMOsCs158QRbFacFbokoA1iw GxSg== X-Gm-Message-State: AKS2vOwe1eHNys06llkI08oYl1BT70RNDuHc6PntbuvtkfbOBVI2pP3V NNRR0GPgurVzzNoisGw= X-Received: by 10.28.19.11 with SMTP id 11mr3145406wmt.123.1497523998970; Thu, 15 Jun 2017 03:53:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 15 Jun 2017 12:52:28 +0200 Message-Id: <1497523981-38449-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1497523981-38449-1-git-send-email-pbonzini@redhat.com> References: <1497523981-38449-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PULL 08/41] megasas: do not read sense length more than once from frame 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Avoid TOC-TOU bugs depending on how the compiler behaves. Signed-off-by: Paolo Bonzini --- hw/scsi/megasas.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index 804122a..1888118 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -309,9 +309,11 @@ static int megasas_build_sense(MegasasCmd *cmd, uint8_= t *sense_ptr, PCIDevice *pcid =3D PCI_DEVICE(cmd->state); uint32_t pa_hi =3D 0, pa_lo; hwaddr pa; + int frame_sense_len; =20 - if (sense_len > cmd->frame->header.sense_len) { - sense_len =3D cmd->frame->header.sense_len; + frame_sense_len =3D cmd->frame->header.sense_len; + if (sense_len > frame_sense_len) { + sense_len =3D frame_sense_len; } if (sense_len) { pa_lo =3D le32_to_cpu(cmd->frame->pass.sense_addr_lo); --=20 1.8.3.1