From nobody Fri May 17 10:44:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612884363; cv=none; d=zohomail.com; s=zohoarc; b=jAcEsbnc0nt2qkpv8V/VqPInCj+cPXqjB9k5/DJPtpk0Zd0VjHHZEoyTCAWW3h9l8zz09q7YbD7ay8b0qbl/6PJ8b579Ja4k8qfFDw+Thha2VdGSNjah/E8my2IV1j5y8iE9eWBeEeTo6NgnZyQsVcIxJSbcXHuIZA7twsBEado= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612884363; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=kEI4vDF0/E1+Fku5FUUjd726RMzTveHrhPMWu5zHuvM=; b=IJhbikIBrLYHYXEEhhasuSid+ka1eeub2hZ3dK4y/S+f3Y7VIebrDle7dxUYryFQyg+Rx2fxwIrmEN5GQflmw4Z8lzR7PcsdDNo2l0cJpzBBjCPSFJQHJxZrZljdUHAi4rEyyG+HPPan3WSkG7IbGuBy/gHELotTRZW2g+JFSyQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612884363460191.76596571016194; Tue, 9 Feb 2021 07:26:03 -0800 (PST) Received: from localhost ([::1]:56728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Utu-00039d-DE for importer@patchew.org; Tue, 09 Feb 2021 10:26:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9Us3-0001fb-WA for qemu-devel@nongnu.org; Tue, 09 Feb 2021 10:24:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31437) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9Urv-00020d-Nk for qemu-devel@nongnu.org; Tue, 09 Feb 2021 10:24:07 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-393-dL3O9zhcM3-KahG6TeCXQw-1; Tue, 09 Feb 2021 10:23:56 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 06D54835E20; Tue, 9 Feb 2021 15:23:55 +0000 (UTC) Received: from blue.redhat.com (ovpn-114-150.phx2.redhat.com [10.3.114.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8BB160CCF; Tue, 9 Feb 2021 15:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612884237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kEI4vDF0/E1+Fku5FUUjd726RMzTveHrhPMWu5zHuvM=; b=dOuFVRj3QVSSHW49TmY8vWYgZuGBs+SYmgZ9oIieWMBn3g1oJmDs3RYlPORC0EGkZNp28D XhR9DYo5+YDo5pXzP2XleOoIV3M4WLghulJlMK5JPZH2LVXgr10ncR6vOxJ38WKBDWNIJ9 Gf0u12uj2C4msMqTI2WjZnhx2fGmTB0= X-MC-Unique: dL3O9zhcM3-KahG6TeCXQw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH] scsi: Silence gcc warning Date: Tue, 9 Feb 2021 09:23:50 -0600 Message-Id: <20210209152350.207958-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Fam Zheng , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) On Fedora 33, gcc 10.2.1 notes that scsi_cdb_length(buf) can set len=3D=3D-1, which in turn overflows g_malloc(): [5/5] Linking target qemu-system-x86_64 In function =E2=80=98scsi_disk_new_request_dump=E2=80=99, inlined from =E2=80=98scsi_new_request=E2=80=99 at ../hw/scsi/scsi-disk= .c:2608:9: ../hw/scsi/scsi-disk.c:2582:19: warning: argument 1 value =E2=80=9818446744= 073709551612=E2=80=99 exceeds maximum object size 9223372036854775807 [-Wal= loc-size-larger-than=3D] 2582 | line_buffer =3D g_malloc(len * 5 + 1); | ^ Silence it with a decent assertion, since we only convert a buffer to bytes when we have a valid cdb length. Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index ed52fcd49ff0..b3311a5657b7 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2579,6 +2579,7 @@ static void scsi_disk_new_request_dump(uint32_t lun, = uint32_t tag, uint8_t *buf) int len =3D scsi_cdb_length(buf); char *line_buffer, *p; + assert(len > 0 && len <=3D 16); line_buffer =3D g_malloc(len * 5 + 1); for (i =3D 0, p =3D line_buffer; i < len; i++) { --=20 2.30.0