From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1fDw-0005xk-Or for qemu-devel@nongnu.org; Wed, 15 Aug 2012 11:09:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1fDr-0001HB-Iw for qemu-devel@nongnu.org; Wed, 15 Aug 2012 11:09:32 -0400 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:44254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1fDr-0001Gv-A4 for qemu-devel@nongnu.org; Wed, 15 Aug 2012 11:09:27 -0400 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 15 Aug 2012 16:09:26 +0100 Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps3074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7FF9GED23068734 for ; Wed, 15 Aug 2012 15:09:16 GMT Received: from d06av05.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7FF9MgB029170 for ; Wed, 15 Aug 2012 09:09:22 -0600 From: Stefan Hajnoczi Date: Wed, 15 Aug 2012 16:09:03 +0100 Message-Id: <1345043344-3978-9-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1345043344-3978-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1345043344-3978-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 8/9] iov_send_recv(): Handle zero bytes case even if OS does not List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Peter Maydell , qemu-devel@nongnu.org, Stefan Hajnoczi From: Peter Maydell POSIX allows sendmsg() and recvmsg() to fail EMSGSIZE if passed a zero msg.msg_iovlen (in particular the MacOS X implementation will do this). Handle the case where iov_send_recv() is passed a zero byte count explicitly, to avoid accidentally depending on the OS to treat zero msg_iovlen as a no-op. Signed-off-by: Peter Maydell Acked-by: Michael Tokarev Signed-off-by: Stefan Hajnoczi --- iov.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iov.c b/iov.c index b333061..60705c7 100644 --- a/iov.c +++ b/iov.c @@ -146,6 +146,13 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, { ssize_t ret; unsigned si, ei; /* start and end indexes */ + if (bytes == 0) { + /* Catch the do-nothing case early, as otherwise we will pass an + * empty iovec to sendmsg/recvmsg(), and not all implementations + * accept this. + */ + return 0; + } /* Find the start position, skipping `offset' bytes: * first, skip all full-sized vector elements, */ -- 1.7.10.4