qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] cadence_gem: Avoid stack-writing buffer-overrun
@ 2012-06-19  6:44 Peter A. G. Crosthwaite
  2012-06-22  9:03 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
  0 siblings, 1 reply; 4+ messages in thread
From: Peter A. G. Crosthwaite @ 2012-06-19  6:44 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Jim Meyering, Peter A. G. Crosthwaite

From: Jim Meyering <meyering@redhat.com>

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>
Signed-off-by: Peter A. G. Crosthwaite <peter.croshtwaite@petalogix.com>
---
 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.3.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-22  9:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-19  6:44 [Qemu-devel] [PATCH] cadence_gem: Avoid stack-writing buffer-overrun Peter A. G. Crosthwaite
2012-06-22  9:03 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
2012-06-22  9:09   ` Peter Maydell
2012-06-22  9:30     ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).