]> git.proxmox.com Git - qemu.git/commitdiff
cadence_gem: avoid stack-writing buffer-overrun
authorJim Meyering <meyering@redhat.com>
Thu, 10 May 2012 06:19:48 +0000 (06:19 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Tue, 19 Jun 2012 13:24:44 +0000 (13:24 +0000)
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 <meyering@redhat.com>
Reviewed-by: Peter A.G. Crosthwaite <peter.crosthwaite@petalogix.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/cadence_gem.c

index e2140aea2bf9471d0bfba7c1aebbbbbbfc25992e..dbde3920d0908b8e81467f9fa445baaa2b828b2e 100644 (file)
@@ -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) {