From nobody Tue Oct 28 12:12:50 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.zohomail.com; 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 1513958420949517.9118673592195; Fri, 22 Dec 2017 08:00:20 -0800 (PST) Received: from localhost ([::1]:55677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSPk6-0006vD-Pj for importer@patchew.org; Fri, 22 Dec 2017 11:00:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSPfU-0003LI-5z for qemu-devel@nongnu.org; Fri, 22 Dec 2017 10:55:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSPfR-0000Cr-KL for qemu-devel@nongnu.org; Fri, 22 Dec 2017 10:55:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSPfR-0000CA-Cl for qemu-devel@nongnu.org; Fri, 22 Dec 2017 10:55:25 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73BCA356DB; Fri, 22 Dec 2017 15:55:24 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-119.ams2.redhat.com [10.36.117.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC6564DC3D; Fri, 22 Dec 2017 15:55:23 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 16:55:22 +0100 Message-Id: <20171222155522.17868-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 22 Dec 2017 15:55:24 +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] scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0 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: rkagan@virtuozzo.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" scsi_disk_emulate_command passes in_buf =3D=3D NULL when sent a REQUEST SENSE command. Check for in_len =3D=3D 0 before dereferencing in_buf. Fixes: f68d98b21fa74155dc7c1fd212474379ac3c7531 Reported-by: Roman Kagan Signed-off-by: Paolo Bonzini Tested-by: Roman Kagan --- scsi/utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scsi/utils.c b/scsi/utils.c index ddae650a99..8738522955 100644 --- a/scsi/utils.c +++ b/scsi/utils.c @@ -322,18 +322,18 @@ int scsi_convert_sense(uint8_t *in_buf, int in_len, SCSISense sense; bool fixed_in; =20 + if (in_len =3D=3D 0) { + return scsi_build_sense_buf(buf, len, SENSE_CODE(NO_SENSE), fixed); + } + fixed_in =3D (in_buf[0] & 2) =3D=3D 0; - if (in_len && fixed =3D=3D fixed_in) { + if (fixed =3D=3D fixed_in) { memcpy(buf, in_buf, MIN(len, in_len)); return MIN(len, in_len); - } - - if (in_len =3D=3D 0) { - sense =3D SENSE_CODE(NO_SENSE); } else { sense =3D scsi_parse_sense_buf(in_buf, in_len); + return scsi_build_sense_buf(buf, len, sense, fixed); } - return scsi_build_sense_buf(buf, len, sense, fixed); } =20 int scsi_sense_to_errno(int key, int asc, int ascq) --=20 2.14.3