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: 10813715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 345DF180E for ; Thu, 14 Feb 2019 20:21:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23FD12F12C for ; Thu, 14 Feb 2019 20:21:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17A782F141; Thu, 14 Feb 2019 20:21:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A0F572F12D for ; Thu, 14 Feb 2019 20:21:29 +0000 (UTC) Received: from localhost ([127.0.0.1]:54473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNVg-0008Kr-Ep for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:21:28 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: 10813733 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F5E96C2 for ; Thu, 14 Feb 2019 20:23:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B80420855 for ; Thu, 14 Feb 2019 20:23:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B48521FAC; Thu, 14 Feb 2019 20:23:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DE3FA20855 for ; Thu, 14 Feb 2019 20:23:53 +0000 (UTC) Received: from localhost ([127.0.0.1]:54521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNY1-0001s4-79 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:23:53 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: 10813741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A2596C2 for ; Thu, 14 Feb 2019 20:26:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28E7C2EB92 for ; Thu, 14 Feb 2019 20:26:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1884E2EC28; Thu, 14 Feb 2019 20:26:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C6AAD2EB92 for ; Thu, 14 Feb 2019 20:26:06 +0000 (UTC) Received: from localhost ([127.0.0.1]:54587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNaA-0004Zv-0X for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:26:06 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: 10813735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2C626C2 for ; Thu, 14 Feb 2019 20:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D33F120855 for ; Thu, 14 Feb 2019 20:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C75E821FAC; Thu, 14 Feb 2019 20:23:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8250C20855 for ; Thu, 14 Feb 2019 20:23:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:54525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNY2-0001t4-QS for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:23:54 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: 10813717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 886771399 for ; Thu, 14 Feb 2019 20:22:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 786CE2EB05 for ; Thu, 14 Feb 2019 20:22:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C8ED2F0E6; Thu, 14 Feb 2019 20:22:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2361E2EB05 for ; Thu, 14 Feb 2019 20:22:05 +0000 (UTC) Received: from localhost ([127.0.0.1]:54515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNWH-0001SL-93 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:22:05 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: 10813737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CECE1399 for ; Thu, 14 Feb 2019 20:24:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D1112EAF1 for ; Thu, 14 Feb 2019 20:24:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41EB12EB62; Thu, 14 Feb 2019 20:24:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E894A2EAF1 for ; Thu, 14 Feb 2019 20:24:33 +0000 (UTC) Received: from localhost ([127.0.0.1]:54542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNYf-0003M9-7Z for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:24:33 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: 10813743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB4426C2 for ; Thu, 14 Feb 2019 20:26:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7F752EB92 for ; Thu, 14 Feb 2019 20:26:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB11A2EC28; Thu, 14 Feb 2019 20:26:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6E90C2EB92 for ; Thu, 14 Feb 2019 20:26:09 +0000 (UTC) Received: from localhost ([127.0.0.1]:54566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNaC-0003n6-OE for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:26:08 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: 10813747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8588D6C2 for ; Thu, 14 Feb 2019 20:28:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 718C52EB18 for ; Thu, 14 Feb 2019 20:28:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60F562EB2E; Thu, 14 Feb 2019 20:28:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0BD082EB18 for ; Thu, 14 Feb 2019 20:28:59 +0000 (UTC) Received: from localhost ([127.0.0.1]:54622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNcw-0006PB-Bs for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:28:58 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: 10813745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1671D1399 for ; Thu, 14 Feb 2019 20:27:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01FAA2EC28 for ; Thu, 14 Feb 2019 20:27:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E74532EE74; Thu, 14 Feb 2019 20:27:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9D2412EC28 for ; Thu, 14 Feb 2019 20:27:52 +0000 (UTC) Received: from localhost ([127.0.0.1]:54609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guNbr-0005mw-OY for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 15:27:51 -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_Lurea?= =?utf-8?q?u?= , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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;