From patchwork Wed Aug 15 15:09:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 177700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E2D8F2C009B for ; Thu, 16 Aug 2012 01:09:55 +1000 (EST) Received: from localhost ([::1]:33949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1fEH-0006DU-Sm for incoming@patchwork.ozlabs.org; Wed, 15 Aug 2012 11:09:53 -0400 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 b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 15 Aug 2012 16:09:23 +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 Received: from localhost (sig-9-145-129-230.de.ibm.com [9.145.129.230]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7FF9Msu029158; Wed, 15 Aug 2012 09:09:22 -0600 From: Stefan Hajnoczi To: Anthony Liguori Date: Wed, 15 Aug 2012 16:09:03 +0100 Message-Id: <1345043344-3978-9-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 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> x-cbid: 12081515-5024-0000-0000-00000383D515 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.107 Cc: Peter Maydell , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 8/9] iov_send_recv(): Handle zero bytes case even if OS does not X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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, */