Received: from eggs.gnu.org ([208.118.235.92]:52903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgyvA-0006Nw-VF for qemu-devel@nongnu.org; Tue, 19 Jun 2012 09:56:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sgyv6-00072L-4n for qemu-devel@nongnu.org; Tue, 19 Jun 2012 09:56:40 -0400 Received: from mnementh.archaic.org.uk ([81.2.115.146]:44844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sgyv5-00072F-TP for qemu-devel@nongnu.org; Tue, 19 Jun 2012 09:56:36 -0400 From: Peter Maydell Date: Tue, 19 Jun 2012 14:31:11 +0100 Message-Id: <1340112673-14846-15-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1340112673-14846-1-git-send-email-peter.maydell@linaro.org> References: <1340112673-14846-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH 14/16] cadence_gem: avoid stack-writing buffer-overrun List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: Anthony Liguori , qemu-devel@nongnu.org, Paul Brook From: Jim Meyering Use sizeof(rxbuf)-size (not sizeof(rxbuf-size)) as the number of bytes to clear. The latter would always clear 4 or 8 bytes, possibly writing beyond the end of that stack buffer. Alternatively, depending on the value of the "size" parameter, it could fail to initialize the end of "rxbuf". Spotted by coverity. Signed-off-by: Jim Meyering Reviewed-by: Peter A.G. Crosthwaite Signed-off-by: Peter Maydell --- hw/cadence_gem.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/hw/cadence_gem.c b/hw/cadence_gem.c index e2140ae..dbde392 100644 --- a/hw/cadence_gem.c +++ b/hw/cadence_gem.c @@ -664,7 +664,7 @@ static ssize_t gem_receive(VLANClientState *nc, const uint8_t *buf, size_t size) */ memcpy(rxbuf, buf, size); - memset(rxbuf + size, 0, sizeof(rxbuf - size)); + memset(rxbuf + size, 0, sizeof(rxbuf) - size); rxbuf_ptr = rxbuf; crc_val = cpu_to_le32(crc32(0, rxbuf, MAX(size, 60))); if (size < 60) { -- 1.7.1