From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O0Ao9-0004Jt-Qs for qemu-devel@nongnu.org; Fri, 09 Apr 2010 05:47:25 -0400 Received: from [140.186.70.92] (port=44304 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O0Ao8-0004IX-0v for qemu-devel@nongnu.org; Fri, 09 Apr 2010 05:47:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O0Ao2-0005wE-4X for qemu-devel@nongnu.org; Fri, 09 Apr 2010 05:47:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41463) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O0Ao1-0005vq-Db for qemu-devel@nongnu.org; Fri, 09 Apr 2010 05:47:18 -0400 From: Kevin Wolf Date: Fri, 9 Apr 2010 11:46:23 +0200 Message-Id: <1270806388-28138-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1270806388-28138-1-git-send-email-kwolf@redhat.com> References: <1270806388-28138-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [STABLE][PATCH 05/10] scsi-disk: fix buffer overflow List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aurelien@aurel32.net Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Gerd Hoffmann In case s->version is shorter than 4 bytes we overflow the memcpy src buffer. Fix it by clearing the target buffer, then copy only the amount of bytes we actually have. Signed-off-by: Gerd Hoffmann Signed-off-by: Anthony Liguori (cherry picked from 314b1811c15f4e982e4667d9b845aee4b5a63d91) Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index b34fbaa..a792012 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -434,7 +434,9 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) memcpy(&outbuf[16], "QEMU HARDDISK ", 16); } memcpy(&outbuf[8], "QEMU ", 8); - memcpy(&outbuf[32], s->version ? s->version : QEMU_VERSION, 4); + memset(&outbuf[32], 0, 4); + memcpy(&outbuf[32], s->version ? s->version : QEMU_VERSION, + MIN(4, strlen(s->version ? s->version : QEMU_VERSION))); /* Identify device as SCSI-3 rev 1. Some later commands are also implemented. */ outbuf[2] = 3; -- 1.6.6.1