From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adq5E-0003Pu-PE for qemu-devel@nongnu.org; Wed, 09 Mar 2016 21:12:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adq59-00005C-OG for qemu-devel@nongnu.org; Wed, 09 Mar 2016 21:12:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adq59-000058-IU for qemu-devel@nongnu.org; Wed, 09 Mar 2016 21:12:07 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 4DAF8C0005D8 for ; Thu, 10 Mar 2016 02:12:07 +0000 (UTC) From: Peter Xu Date: Thu, 10 Mar 2016 10:11:54 +0800 Message-Id: <1457575914-15581-1-git-send-email-peterx@redhat.com> Subject: [Qemu-devel] [PATCH] usb: fix unbounded stack warning for xhci_dma_write_u32s List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, kraxel@redhat.com, peterx@redhat.com Signed-off-by: Peter Xu --- hw/usb/hcd-xhci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 44b6f8c..d15918f 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -698,11 +698,13 @@ static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr, uint32_t *buf, size_t len) { int i; - uint32_t tmp[len / sizeof(uint32_t)]; + uint32_t tmp[12]; + uint32_t n = len / sizeof(uint32_t); assert((len % sizeof(uint32_t)) == 0); + assert(n <= ARRAY_SIZE(tmp)); - for (i = 0; i < (len / sizeof(uint32_t)); i++) { + for (i = 0; i < n; i++) { tmp[i] = cpu_to_le32(buf[i]); } pci_dma_write(PCI_DEVICE(xhci), addr, tmp, len); -- 2.4.3