From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bopP0-0004If-4d for qemu-devel@nongnu.org; Tue, 27 Sep 2016 06:14:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bopOy-0004O0-7s for qemu-devel@nongnu.org; Tue, 27 Sep 2016 06:14:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bopOy-0004Ns-1e for qemu-devel@nongnu.org; Tue, 27 Sep 2016 06:14:16 -0400 From: Jason Wang Date: Tue, 27 Sep 2016 18:12:57 +0800 Message-Id: <1474971187-15627-18-git-send-email-jasowang@redhat.com> In-Reply-To: <1474971187-15627-1-git-send-email-jasowang@redhat.com> References: <1474971187-15627-1-git-send-email-jasowang@redhat.com> Subject: [Qemu-devel] [PULL V2 17/27] 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: peter.maydell@linaro.org, Peter Lieven , Jason Wang From: 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 Reviewed-by: Stefan Hajnoczi Signed-off-by: Jason Wang --- net/net.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/net.c b/net/net.c index 0bec096..ec984bf 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) { -- 2.7.4