From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahxjJ-0006pw-Cn for qemu-devel@nongnu.org; Mon, 21 Mar 2016 07:10:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahxjF-0001ik-9D for qemu-devel@nongnu.org; Mon, 21 Mar 2016 07:10:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahxjF-0001iU-2V for qemu-devel@nongnu.org; Mon, 21 Mar 2016 07:10:33 -0400 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 CB8E1C049E1C for ; Mon, 21 Mar 2016 11:10:32 +0000 (UTC) From: Gerd Hoffmann Date: Mon, 21 Mar 2016 12:10:20 +0100 Message-Id: <1458558624-6890-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1458558624-6890-1-git-send-email-kraxel@redhat.com> References: <1458558624-6890-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PULL 2/6] 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: Gerd Hoffmann , Peter Xu From: Peter Xu All the callers for xhci_dma_write_u32s() are using mostly 5 * uint32_t in len. To avoid unbound stack warning for the function, make it statically allocated, and assert when it's not big enough in the future. Signed-off-by: Peter Xu Message-id: 1457661106-9569-1-git-send-email-peterx@redhat.com Signed-off-by: Gerd Hoffmann --- 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..bcde8a2 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[5]; + 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); -- 1.8.3.1