From patchwork Thu Feb 14 20:19:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042388 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440npF4GDwz9sCh for ; Fri, 15 Feb 2019 07:20:51 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNV0-0008Kr-IR for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:20:46 -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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Marc-André 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 = opaque; - return VSCARD_IN_SIZE >= card->vscard_in_pos ? - VSCARD_IN_SIZE - card->vscard_in_pos : 0; + assert(card->vscard_in_pos <= VSCARD_IN_SIZE); + return VSCARD_IN_SIZE - card->vscard_in_pos; } static void ccid_card_vscard_handle_init( @@ -282,7 +282,6 @@ static void ccid_card_vscard_read(void *opaque, const uint8_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 += size; From patchwork Thu Feb 14 20:19:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042392 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440ns950HSz9s5c for ; Fri, 15 Feb 2019 07:23:25 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNXX-0001s4-Ka for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:23:23 -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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Arash Tohidi Chafi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 >= 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é --- 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(PassthruState *card, } } -static void ccid_card_vscard_drop_connection(PassthruState *card) -{ - qemu_chr_fe_deinit(&card->cs, true); - card->vscard_in_pos = card->vscard_in_hdr = 0; -} - static void ccid_card_vscard_read(void *opaque, const uint8_t *buf, int size) { PassthruState *card = opaque; VSCMsgHeader *hdr; - 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 <= 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 += size; From patchwork Thu Feb 14 20:19:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440nvt2RHRz9rxp for ; Fri, 15 Feb 2019 07:25:46 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNZo-0003lx-8k for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:25:44 -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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daudé --- 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 uint8_t *buf, int size) VSCMsgHeader *hdr; assert(size <= 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 += size; hdr = (VSCMsgHeader *)(card->vscard_in_data + card->vscard_in_hdr); From patchwork Thu Feb 14 20:19:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440nsF3dL0z9rxp for ; Fri, 15 Feb 2019 07:23:29 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNXZ-0001t4-4w for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:23:25 -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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daudé --- 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 += hdr->length + sizeof(VSCMsgHeader); hdr = (VSCMsgHeader *)(card->vscard_in_data + card->vscard_in_hdr); } - if (card->vscard_in_hdr == card->vscard_in_pos) { - card->vscard_in_pos = card->vscard_in_hdr = 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 -= card->vscard_in_hdr; + card->vscard_in_hdr = 0; } } From patchwork Thu Feb 14 20:19:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042390 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440nq50LQ4z9rxp for ; Fri, 15 Feb 2019 07:21:37 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNVn-0000Si-0r for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:21: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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Marc-André 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 +/* maximum size of ATR - from 7816-3 */ +#define MAX_ATR_SIZE 40 + /* TODO: do we still need this? */ static const uint8_t DEFAULT_ATR[] = { /* @@ -41,10 +44,9 @@ static const uint8_t DEFAULT_ATR[] = { 0x13, 0x08 }; -#define VSCARD_IN_SIZE (64 * KiB) +QEMU_BUILD_BUG_ON(sizeof(DEFAULT_ATR) > MAX_ATR_SIZE); -/* maximum size of ATR - from 7816-3 */ -#define MAX_ATR_SIZE 40 +#define VSCARD_IN_SIZE (64 * KiB) typedef struct PassthruState PassthruState; @@ -351,7 +353,6 @@ static void passthru_realize(CCIDCardState *base, Error **errp) } card->debug = parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE, card->debug); - assert(sizeof(DEFAULT_ATR) <= MAX_ATR_SIZE); memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR)); card->atr_length = sizeof(DEFAULT_ATR); } From patchwork Thu Feb 14 20:19:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042394 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440nsw44xLz9rxp for ; Fri, 15 Feb 2019 07:24:04 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNYA-0002Lk-Dy for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:24:02 -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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Simplify the if() condition so we can remove an indent layer and the code is easier to review. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Marc-André 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, Error **errp) { PassthruState *card = PASSTHRU_CCID_CARD(base); - card->vscard_in_pos = 0; - card->vscard_in_hdr = 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 = 0; + card->vscard_in_hdr = 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 = parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE, card->debug); memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR)); From patchwork Thu Feb 14 20:19:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440nvw5ZvMz9rxp for ; Fri, 15 Feb 2019 07:25:48 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNZq-0003n6-Nm for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:25:46 -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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Philippe Mathieu-Daudé --- 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" #define DPRINTF(card, lvl, fmt, ...) \ do { \ @@ -339,7 +340,7 @@ static void passthru_realize(CCIDCardState *base, Error **errp) PassthruState *card = PASSTHRU_CCID_CARD(base); 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 = 0; From patchwork Thu Feb 14 20:19:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440nzK6yMjz9rxp for ; Fri, 15 Feb 2019 07:28:45 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNch-00066c-Um for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:28:43 -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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Marc-André 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); } -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 = 0; int td; @@ -185,18 +186,18 @@ static int check_atr(PassthruState *card, uint8_t *data, 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 optional\n", len, historical_length, opt_bytes); return 1; From patchwork Thu Feb 14 20:19:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1042397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440ny23qhyz9rxp for ; Fri, 15 Feb 2019 07:27:38 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNbc-0005Kl-H1 for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2019 15:27:36 -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_Mathieu-Daud=C3=A9?= To: Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lur?= =?utf-8?q?eau?= , 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) 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_Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The variable 'opt_bytes' is an index to the data[] array. Use size_t for indexes. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Marc-André 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 = 0; int td; @@ -192,12 +192,13 @@ static int check_atr(PassthruState *card, uint8_t *data, 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 optional\n", + "atr passes check: %zu total length," + " %zu historical, %zu optional\n", len, historical_length, opt_bytes); return 1;