From patchwork Tue Mar 8 07:00:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 8530031 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6692F9F372 for ; Tue, 8 Mar 2016 07:02:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CCE402017D for ; Tue, 8 Mar 2016 07:02:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 250872015E for ; Tue, 8 Mar 2016 07:02:45 +0000 (UTC) Received: from localhost ([::1]:60750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adBfI-0004t3-IB for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 Mar 2016 02:02:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adBe7-0002kx-5E for qemu-devel@nongnu.org; Tue, 08 Mar 2016 02:01:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adBe1-0006Rl-CL for qemu-devel@nongnu.org; Tue, 08 Mar 2016 02:01:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44708) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adBe1-0006Ra-7c for qemu-devel@nongnu.org; Tue, 08 Mar 2016 02:01:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 9D2DC8E00D for ; Tue, 8 Mar 2016 07:01:24 +0000 (UTC) Received: from pxdev.xzpeter.org.com (vpn1-5-232.pek2.redhat.com [10.72.5.232]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2870qvN019713; Tue, 8 Mar 2016 02:01:18 -0500 From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 8 Mar 2016 15:00:41 +0800 Message-Id: <1457420446-25276-4-git-send-email-peterx@redhat.com> In-Reply-To: <1457420446-25276-1-git-send-email-peterx@redhat.com> References: <1457420446-25276-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, Gerd Hoffmann , peterx@redhat.com Subject: [Qemu-devel] [PATCH 3/8] usb: fix unbounded stack for ohci_td_pkt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Suggested-by: Paolo Bonzini CC: Gerd Hoffmann Signed-off-by: Peter Xu --- hw/usb/hcd-ohci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 17ed461..c3cd4e2 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -936,11 +936,11 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, #ifdef trace_event_get_state static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len) { +#define __TEMP_WIDTH (16) bool print16 = !!trace_event_get_state(TRACE_USB_OHCI_TD_PKT_SHORT); bool printall = !!trace_event_get_state(TRACE_USB_OHCI_TD_PKT_FULL); - const int width = 16; int i; - char tmp[3 * width + 1]; + char tmp[3 * __TEMP_WIDTH + 1]; char *p = tmp; if (!printall && !print16) { @@ -948,7 +948,7 @@ static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len) } for (i = 0; ; i++) { - if (i && (!(i % width) || (i == len))) { + if (i && (!(i % __TEMP_WIDTH) || (i == len))) { if (!printall) { trace_usb_ohci_td_pkt_short(msg, tmp); break; @@ -963,6 +963,7 @@ static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len) p += sprintf(p, " %.2x", buf[i]); } +#undef __TEMP_WIDTH } #else static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len)