From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ld8mZ-0008BR-Os for qemu-devel@nongnu.org; Fri, 27 Feb 2009 14:54:03 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ld8mZ-0008Ah-0o for qemu-devel@nongnu.org; Fri, 27 Feb 2009 14:54:03 -0500 Received: from [199.232.76.173] (port=40341 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ld8mY-0008AF-Nt for qemu-devel@nongnu.org; Fri, 27 Feb 2009 14:54:02 -0500 Received: from savannah.gnu.org ([199.232.41.3]:37358 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ld8mY-0005hM-GD for qemu-devel@nongnu.org; Fri, 27 Feb 2009 14:54:02 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1Ld8mY-0007Vk-1R for qemu-devel@nongnu.org; Fri, 27 Feb 2009 19:54:02 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1Ld8mX-0007Vg-T3 for qemu-devel@nongnu.org; Fri, 27 Feb 2009 19:54:01 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Fri, 27 Feb 2009 19:54:01 +0000 Subject: [Qemu-devel] [6647] net socket verify packet size (Dustin Kirkland) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6647 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6647 Author: aliguori Date: 2009-02-27 19:54:01 +0000 (Fri, 27 Feb 2009) Log Message: ----------- net socket verify packet size (Dustin Kirkland) net socket oversized packet This is a patch being carried by Ubuntu against kvm/qemu. Verify packet size before performing memcpy(). Signed-off-by: Dustin Kirkland Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/net.c Modified: trunk/net.c =================================================================== --- trunk/net.c 2009-02-27 19:53:57 UTC (rev 6646) +++ trunk/net.c 2009-02-27 19:54:01 UTC (rev 6647) @@ -1093,8 +1093,8 @@ VLANClientState *vc; int fd; int state; /* 0 = getting length, 1 = getting data */ - int index; - int packet_len; + unsigned int index; + unsigned int packet_len; uint8_t buf[4096]; struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */ } NetSocketState; @@ -1127,7 +1127,8 @@ static void net_socket_send(void *opaque) { NetSocketState *s = opaque; - int l, size, err; + int size, err; + unsigned l; uint8_t buf1[4096]; const uint8_t *buf; @@ -1166,7 +1167,15 @@ l = s->packet_len - s->index; if (l > size) l = size; - memcpy(s->buf + s->index, buf, l); + if (s->index + l <= sizeof(s->buf)) { + memcpy(s->buf + s->index, buf, l); + } else { + fprintf(stderr, "serious error: oversized packet received," + "connection terminated.\n"); + s->state = 0; + goto eoc; + } + s->index += l; buf += l; size -= l;