From: Jim Meyering <jim@meyering.net>
To: qemu-devel@nongnu.org
Cc: Jim Meyering <meyering@redhat.com>,
Peter Crosthwaite <peter.crosthwaite@petalogix.com>
Subject: [Qemu-devel] [PATCH 2/2] cadence_gem: avoid stack-writing buffer-overrun
Date: Thu, 10 May 2012 18:19:48 +0200 [thread overview]
Message-ID: <1336666788-30233-3-git-send-email-jim@meyering.net> (raw)
In-Reply-To: <1336666788-30233-1-git-send-email-jim@meyering.net>
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>
---
hw/cadence_gem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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.10.1.487.ga3935e6
next prev parent reply other threads:[~2012-05-10 16:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-10 16:19 [Qemu-devel] [PATCH 0/2] memset/sizeof abuse Jim Meyering
2012-05-10 16:19 ` [Qemu-devel] [PATCH 1/2] kvm/apic: correct short memset Jim Meyering
2012-05-10 17:28 ` Jan Kiszka
2012-05-22 20:30 ` [Qemu-devel] [PATCH 1.1 " Stefan Weil
2012-05-23 10:33 ` Jan Kiszka
2012-06-10 20:29 ` Stefan Weil
2012-06-11 5:29 ` Jan Kiszka
2012-06-11 9:58 ` [Qemu-devel] [PATCH " Avi Kivity
2012-05-10 16:19 ` Jim Meyering [this message]
2012-05-14 4:57 ` [Qemu-devel] [PATCH 2/2] cadence_gem: avoid stack-writing buffer-overrun Peter Crosthwaite
2012-06-10 20:34 ` Stefan Weil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1336666788-30233-3-git-send-email-jim@meyering.net \
--to=jim@meyering.net \
--cc=meyering@redhat.com \
--cc=peter.crosthwaite@petalogix.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).