Received: from eggs.gnu.org ([2001:4830:134:3::10]:56588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIYbf-0001mw-AM for qemu-devel@nongnu.org; Thu, 30 Jun 2016 05:50:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIYbZ-0003yc-DD for qemu-devel@nongnu.org; Thu, 30 Jun 2016 05:49:58 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:58777 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIYbZ-0003yN-2n for qemu-devel@nongnu.org; Thu, 30 Jun 2016 05:49:53 -0400 From: Peter Lieven Date: Thu, 30 Jun 2016 11:49:40 +0200 Message-Id: <1467280180-9234-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCH] net: limit allocation in nc_sendv_compat List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, dhannawatpooja1@gmail.com, jasowang@redhat.com, Peter Lieven we only need to allocate enough memory to hold the packet. This might be less than NET_BUFSIZE. Additionally fail early if the packet is larger than NET_BUFSIZE. Signed-off-by: Peter Lieven --- net/net.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/net.c b/net/net.c index 5f3e5a9..54a578d 100644 --- a/net/net.c +++ b/net/net.c @@ -690,9 +690,13 @@ static ssize_t nc_sendv_compat(NetClientState *nc, const struct iovec *iov, buffer = iov[0].iov_base; offset = iov[0].iov_len; } else { - buf = g_new(uint8_t, NET_BUFSIZE); + offset = iov_size(iov, iovcnt); + if (offset > NET_BUFSIZE) { + return -1; + } + buf = g_malloc(offset); buffer = buf; - offset = iov_to_buf(iov, iovcnt, 0, buf, NET_BUFSIZE); + offset = iov_to_buf(iov, iovcnt, 0, buf, offset); } if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) { -- 1.9.1