From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550175721525519.292833028763; Thu, 14 Feb 2019 12:22:01 -0800 (PST) Received: from localhost ([127.0.0.1]:54509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNW9-000104-0O for importer@patchew.org; Thu, 14 Feb 2019 15:21:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNUH-0008FX-Uh for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNUF-00054b-Bt for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNUF-0004zo-3Y for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:19:59 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACC1640F19; Thu, 14 Feb 2019 20:19:57 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA96F19C65; Thu, 14 Feb 2019 20:19:54 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:31 +0100 Message-Id: <20190214201939.494-2-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 14 Feb 2019 20:19:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/9] ccid-card-passthru: Move assertion in read() to can_read() 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" chardev::read() depends of what chardev::can_read() returns, move the assertion to can_read(). Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/usb/ccid-card-passthru.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 0a6c657228..8bb1314f49 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -116,8 +116,8 @@ static int ccid_card_vscard_can_read(void *opaque) { PassthruState *card =3D opaque; =20 - return VSCARD_IN_SIZE >=3D card->vscard_in_pos ? - VSCARD_IN_SIZE - card->vscard_in_pos : 0; + assert(card->vscard_in_pos <=3D VSCARD_IN_SIZE); + return VSCARD_IN_SIZE - card->vscard_in_pos; } =20 static void ccid_card_vscard_handle_init( @@ -282,7 +282,6 @@ static void ccid_card_vscard_read(void *opaque, const u= int8_t *buf, int size) ccid_card_vscard_drop_connection(card); return; } - assert(card->vscard_in_pos < VSCARD_IN_SIZE); assert(card->vscard_in_hdr < VSCARD_IN_SIZE); memcpy(card->vscard_in_data + card->vscard_in_pos, buf, size); card->vscard_in_pos +=3D size; --=20 2.20.1 From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550175864425210.42803865216206; Thu, 14 Feb 2019 12:24:24 -0800 (PST) Received: from localhost ([127.0.0.1]:54536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNYS-0002i3-Bb for importer@patchew.org; Thu, 14 Feb 2019 15:24:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNUN-0008Ml-DV for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNUI-0005BC-Ps for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54360) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNUI-00059N-Al for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C11481259; Thu, 14 Feb 2019 20:20:01 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E82D19C65; Thu, 14 Feb 2019 20:19:58 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:32 +0100 Message-Id: <20190214201939.494-3-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 14 Feb 2019 20:20:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/9] ccid-card-passthru: Replace never trigger if statement by an assertion 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Arash Tohidi Chafi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The right side of the comparison is the return value of can_read(): VSCARD_IN_SIZE - card->vscard_in_pos. Since the 'size' argument of chardev::read() is bound to what chardev::can_read() returns, this condition can never happen. Add an assertion, which will always fail if card->vscard_in_pos >=3D VSCARD_IN_SIZE), since size > 0. This is a quick fix for CVE-2018-18438 "Integer overflow in ccid_card_vscard_read() allows memory corruption". Fixes: CVE-2018-18438 Reported-by: Arash Tohidi Chafi Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/usb/ccid-card-passthru.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 8bb1314f49..1676b5fc05 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -264,24 +264,12 @@ static void ccid_card_vscard_handle_message(PassthruS= tate *card, } } =20 -static void ccid_card_vscard_drop_connection(PassthruState *card) -{ - qemu_chr_fe_deinit(&card->cs, true); - card->vscard_in_pos =3D card->vscard_in_hdr =3D 0; -} - static void ccid_card_vscard_read(void *opaque, const uint8_t *buf, int si= ze) { PassthruState *card =3D opaque; VSCMsgHeader *hdr; =20 - if (card->vscard_in_pos + size > VSCARD_IN_SIZE) { - error_report("no room for data: pos %u + size %d > %" PRId64 "." - " dropping connection.", - card->vscard_in_pos, size, VSCARD_IN_SIZE); - ccid_card_vscard_drop_connection(card); - return; - } + assert(size <=3D VSCARD_IN_SIZE - card->vscard_in_pos); assert(card->vscard_in_hdr < VSCARD_IN_SIZE); memcpy(card->vscard_in_data + card->vscard_in_pos, buf, size); card->vscard_in_pos +=3D size; --=20 2.20.1 From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550175994045803.4609433809084; Thu, 14 Feb 2019 12:26:34 -0800 (PST) Received: from localhost ([127.0.0.1]:54587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNaU-0004Zv-2q for importer@patchew.org; Thu, 14 Feb 2019 15:26:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNUX-00007x-GN for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNUV-0005Tc-T4 for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39094) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNUV-0005PY-E0 for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:15 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 215DF2C9C9F; Thu, 14 Feb 2019 20:20:13 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2B1E19745; Thu, 14 Feb 2019 20:20:01 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:33 +0100 Message-Id: <20190214201939.494-4-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 14 Feb 2019 20:20:13 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/9] ccid-card-passthru: Assert on a stricter expression 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/usb/ccid-card-passthru.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 1676b5fc05..0c44b38fc2 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -270,7 +270,7 @@ static void ccid_card_vscard_read(void *opaque, const u= int8_t *buf, int size) VSCMsgHeader *hdr; =20 assert(size <=3D VSCARD_IN_SIZE - card->vscard_in_pos); - assert(card->vscard_in_hdr < VSCARD_IN_SIZE); + assert(card->vscard_in_hdr < card->vscard_in_pos); memcpy(card->vscard_in_data + card->vscard_in_pos, buf, size); card->vscard_in_pos +=3D size; hdr =3D (VSCMsgHeader *)(card->vscard_in_data + card->vscard_in_hdr); --=20 2.20.1 From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550175868455411.71902788441685; Thu, 14 Feb 2019 12:24:28 -0800 (PST) Received: from localhost ([127.0.0.1]:54538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNYW-0002jP-Ec for importer@patchew.org; Thu, 14 Feb 2019 15:24:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNUp-0000NE-CO for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNUn-0005n8-FW for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54454) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNUd-0005Ux-RF for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:25 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A47E880E5D; Thu, 14 Feb 2019 20:20:16 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3DB319C65; Thu, 14 Feb 2019 20:20:13 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:34 +0100 Message-Id: <20190214201939.494-5-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 14 Feb 2019 20:20:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/9] ccid-card-passthru: Let the chardev::read() be more generic 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/usb/ccid-card-passthru.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 0c44b38fc2..ba7c285ded 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -285,8 +285,14 @@ static void ccid_card_vscard_read(void *opaque, const = uint8_t *buf, int size) card->vscard_in_hdr +=3D hdr->length + sizeof(VSCMsgHeader); hdr =3D (VSCMsgHeader *)(card->vscard_in_data + card->vscard_in_hd= r); } - if (card->vscard_in_hdr =3D=3D card->vscard_in_pos) { - card->vscard_in_pos =3D card->vscard_in_hdr =3D 0; + + /* Drop any messages that were fully processed. */ + if (card->vscard_in_hdr > 0) { + memmove(card->vscard_in_data, + card->vscard_in_data + card->vscard_in_hdr, + card->vscard_in_pos - card->vscard_in_hdr); + card->vscard_in_pos -=3D card->vscard_in_hdr; + card->vscard_in_hdr =3D 0; } } =20 --=20 2.20.1 From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550175759884132.04471875176148; Thu, 14 Feb 2019 12:22:39 -0800 (PST) Received: from localhost ([127.0.0.1]:54515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNWl-0001SL-Rs for importer@patchew.org; Thu, 14 Feb 2019 15:22:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNUt-0000QV-CD for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNUp-0005p0-Df for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNUl-0005YP-J5 for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86D8A81259; Thu, 14 Feb 2019 20:20:19 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4FBDA19C65; Thu, 14 Feb 2019 20:20:17 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:35 +0100 Message-Id: <20190214201939.494-6-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 14 Feb 2019 20:20:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/9] ccid-card-passthru: Replace assert() by QEMU_BUILD_BUG_ON() 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/usb/ccid-card-passthru.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index ba7c285ded..ccc3ffa7fa 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -29,6 +29,9 @@ do { \ #define D_MORE_INFO 3 #define D_VERBOSE 4 =20 +/* maximum size of ATR - from 7816-3 */ +#define MAX_ATR_SIZE 40 + /* TODO: do we still need this? */ static const uint8_t DEFAULT_ATR[] =3D { /* @@ -41,10 +44,9 @@ static const uint8_t DEFAULT_ATR[] =3D { 0x13, 0x08 }; =20 -#define VSCARD_IN_SIZE (64 * KiB) +QEMU_BUILD_BUG_ON(sizeof(DEFAULT_ATR) > MAX_ATR_SIZE); =20 -/* maximum size of ATR - from 7816-3 */ -#define MAX_ATR_SIZE 40 +#define VSCARD_IN_SIZE (64 * KiB) =20 typedef struct PassthruState PassthruState; =20 @@ -351,7 +353,6 @@ static void passthru_realize(CCIDCardState *base, Error= **errp) } card->debug =3D parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE, card->debug); - assert(sizeof(DEFAULT_ATR) <=3D MAX_ATR_SIZE); memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR)); card->atr_length =3D sizeof(DEFAULT_ATR); } --=20 2.20.1 From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550175907807321.21578457100327; Thu, 14 Feb 2019 12:25:07 -0800 (PST) Received: from localhost ([127.0.0.1]:54542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNZ5-0003M9-2a for importer@patchew.org; Thu, 14 Feb 2019 15:24:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNV4-0000aR-Sg for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNV2-000614-FJ for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60290) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNUx-0005ce-H1 for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:45 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6AEB4B8A; Thu, 14 Feb 2019 20:20:22 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4771419C65; Thu, 14 Feb 2019 20:20:19 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:36 +0100 Message-Id: <20190214201939.494-7-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 14 Feb 2019 20:20:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 6/9] ccid-card-passthru: Simplify the if() condition 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Simplify the if() condition so we can remove an indent layer and the code is easier to review. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/usb/ccid-card-passthru.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index ccc3ffa7fa..6cb8b2d26b 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -338,19 +338,17 @@ static void passthru_realize(CCIDCardState *base, Err= or **errp) { PassthruState *card =3D PASSTHRU_CCID_CARD(base); =20 - card->vscard_in_pos =3D 0; - card->vscard_in_hdr =3D 0; - if (qemu_chr_fe_backend_connected(&card->cs)) { - DPRINTF(card, D_INFO, "ccid-card-passthru: initing chardev"); - qemu_chr_fe_set_handlers(&card->cs, - ccid_card_vscard_can_read, - ccid_card_vscard_read, - ccid_card_vscard_event, NULL, card, NULL, true); - ccid_card_vscard_send_init(card); - } else { + if (!qemu_chr_fe_backend_connected(&card->cs)) { error_setg(errp, "missing chardev"); return; } + card->vscard_in_pos =3D 0; + card->vscard_in_hdr =3D 0; + DPRINTF(card, D_INFO, "ccid-card-passthru: initing chardev"); + qemu_chr_fe_set_handlers(&card->cs, ccid_card_vscard_can_read, + ccid_card_vscard_read, ccid_card_vscard_event, + NULL, card, NULL, true); + ccid_card_vscard_send_init(card); card->debug =3D parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE, card->debug); memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR)); --=20 2.20.1 From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550175994545615.1588758177818; Thu, 14 Feb 2019 12:26:34 -0800 (PST) Received: from localhost ([127.0.0.1]:54589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNaX-0004bc-GA for importer@patchew.org; Thu, 14 Feb 2019 15:26:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNV2-0000YB-EA for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNUx-0005vu-Di for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41678) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNUt-0005pb-9H for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:39 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E5663DBE2; Thu, 14 Feb 2019 20:20:35 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C10D19745; Thu, 14 Feb 2019 20:20:23 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:37 +0100 Message-Id: <20190214201939.494-8-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 14 Feb 2019 20:20:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 7/9] ccid-card-passthru: Use QERR_MISSING_PARAMETER 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/usb/ccid-card-passthru.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 6cb8b2d26b..d63aa28584 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -16,6 +16,7 @@ #include "qemu/sockets.h" #include "ccid.h" #include "qapi/error.h" +#include "qapi/qmp/qerror.h" =20 #define DPRINTF(card, lvl, fmt, ...) \ do { \ @@ -339,7 +340,7 @@ static void passthru_realize(CCIDCardState *base, Error= **errp) PassthruState *card =3D PASSTHRU_CCID_CARD(base); =20 if (!qemu_chr_fe_backend_connected(&card->cs)) { - error_setg(errp, "missing chardev"); + error_setg(errp, QERR_MISSING_PARAMETER, "chardev"); return; } card->vscard_in_pos =3D 0; --=20 2.20.1 From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550176152614996.0546781102485; Thu, 14 Feb 2019 12:29:12 -0800 (PST) Received: from localhost ([127.0.0.1]:54622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNd8-0006PB-ME for importer@patchew.org; Thu, 14 Feb 2019 15:29:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNVB-0000cT-Ow for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:21:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNVA-00068A-JB for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60498) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNV7-0005rk-1u for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3E1EBBA9; Thu, 14 Feb 2019 20:20:38 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27DDD19C65; Thu, 14 Feb 2019 20:20:35 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:38 +0100 Message-Id: <20190214201939.494-9-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 14 Feb 2019 20:20:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 8/9] ccid-card-passthru: Use size_t to hold size argument 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" check_atr() is called once with a unsigned argument. Since there is no need to use a signed type, use a size_t. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/usb/ccid-card-passthru.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index d63aa28584..083eb5ca08 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -149,9 +149,10 @@ static void ccid_card_vscard_handle_init( ccid_card_vscard_send_init(card); } =20 -static int check_atr(PassthruState *card, uint8_t *data, int len) +static int check_atr(PassthruState *card, uint8_t *data, size_t len) { - int historical_length, opt_bytes; + size_t historical_length; + int opt_bytes; int td_count =3D 0; int td; =20 @@ -185,18 +186,18 @@ static int check_atr(PassthruState *card, uint8_t *da= ta, int len) } if (len < 2 + historical_length + opt_bytes) { DPRINTF(card, D_WARN, - "atr too short: len %d, but historical_len %d, T1 0x%X\n", + "atr too short: len %zu, but historical_len %zu, T1 0x%X\n", len, historical_length, data[1]); return 0; } if (len > 2 + historical_length + opt_bytes) { DPRINTF(card, D_WARN, - "atr too long: len %d, but hist/opt %d/%d, T1 0x%X\n", + "atr too long: len %zu, but hist/opt %zu/%d, T1 0x%X\n", len, historical_length, opt_bytes, data[1]); /* let it through */ } DPRINTF(card, D_VERBOSE, - "atr passes check: %d total length, %d historical, %d optional= \n", + "atr passes check: %zu total length, %zu historical, %d option= al\n", len, historical_length, opt_bytes); =20 return 1; --=20 2.20.1 From nobody Thu Nov 6 02:09:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550176086662550.0851686402277; Thu, 14 Feb 2019 12:28:06 -0800 (PST) Received: from localhost ([127.0.0.1]:54609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNc4-0005mw-Gw for importer@patchew.org; Thu, 14 Feb 2019 15:28:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNVA-0000cA-L3 for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guNV8-00066I-O6 for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guNV6-0005vy-SI for qemu-devel@nongnu.org; Thu, 14 Feb 2019 15:20:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4459273A8E; Thu, 14 Feb 2019 20:20:43 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8405C19C65; Thu, 14 Feb 2019 20:20:39 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org, Paolo Bonzini Date: Thu, 14 Feb 2019 21:19:39 +0100 Message-Id: <20190214201939.494-10-philmd@redhat.com> In-Reply-To: <20190214201939.494-1-philmd@redhat.com> References: <20190214201939.494-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 14 Feb 2019 20:20:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 9/9] ccid-card-passthru: Use size_t for index 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The variable 'opt_bytes' is an index to the data[] array. Use size_t for indexes. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/usb/ccid-card-passthru.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 083eb5ca08..664e8a1b54 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -152,7 +152,7 @@ static void ccid_card_vscard_handle_init( static int check_atr(PassthruState *card, uint8_t *data, size_t len) { size_t historical_length; - int opt_bytes; + size_t opt_bytes; int td_count =3D 0; int td; =20 @@ -192,12 +192,13 @@ static int check_atr(PassthruState *card, uint8_t *da= ta, size_t len) } if (len > 2 + historical_length + opt_bytes) { DPRINTF(card, D_WARN, - "atr too long: len %zu, but hist/opt %zu/%d, T1 0x%X\n", + "atr too long: len %zu, but hist/opt %zu/%zu, T1 0x%X\n", len, historical_length, opt_bytes, data[1]); /* let it through */ } DPRINTF(card, D_VERBOSE, - "atr passes check: %zu total length, %zu historical, %d option= al\n", + "atr passes check: %zu total length," + " %zu historical, %zu optional\n", len, historical_length, opt_bytes); =20 return 1; --=20 2.20.1