From patchwork Tue Aug 2 09:41:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shmulik Ladkani X-Patchwork-Id: 654624 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s3WVX31WWz9t3F for ; Tue, 2 Aug 2016 19:43:48 +1000 (AEST) Received: from localhost ([::1]:54956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUWEk-0005zk-4Y for incoming@patchwork.ozlabs.org; Tue, 02 Aug 2016 05:43:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUWDW-000534-2e for qemu-devel@nongnu.org; Tue, 02 Aug 2016 05:42:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUWDQ-0006Cr-3J for qemu-devel@nongnu.org; Tue, 02 Aug 2016 05:42:28 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:32572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUWDP-0006CK-QT for qemu-devel@nongnu.org; Tue, 02 Aug 2016 05:42:24 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u729gHPh024080 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 2 Aug 2016 09:42:18 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u729gHPm007572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 2 Aug 2016 09:42:17 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u729gGac025016; Tue, 2 Aug 2016 09:42:17 GMT Received: from honey.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 02 Aug 2016 02:42:16 -0700 From: Shmulik Ladkani To: "Michael S. Tsirkin" , Paolo Bonzini , qemu-devel@nongnu.org Date: Tue, 2 Aug 2016 12:41:20 +0300 Message-Id: <1470130880-1050-1-git-send-email-shmulik.ladkani@oracle.com> X-Mailer: git-send-email 1.9.1 X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 Subject: [Qemu-devel] [PATCH v2] util: Fix assertion in iov_copy() upon zero 'bytes' and non-zero 'offset' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fleytman , Jason Wang , Shmulik Ladkani Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Shmulik Ladkani In cases where iov_copy() is passed with zero 'bytes' argument and a non-zero 'offset' argument, nothing gets copied - as expected. However no copy iterations are performed, so 'offset' is left unaltered, leading to the final assert(offset == 0) to fail. Instead, change the loop condition to continue as long as 'offset || bytes', similar to other iov_* functions. This ensures 'offset' gets zeroed (even if no actual copy is made), unless it is beyond end of source iov - which is asserted. Signed-off-by: Shmulik Ladkani --- util/iov.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) v2: Instead of relaxing the assertion, modify loop condition, as suggested by Paolo diff --git a/util/iov.c b/util/iov.c index 003fcce..74e6ca8 100644 --- a/util/iov.c +++ b/util/iov.c @@ -247,7 +247,8 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt, { size_t len; unsigned int i, j; - for (i = 0, j = 0; i < iov_cnt && j < dst_iov_cnt && bytes; i++) { + for (i = 0, j = 0; + i < iov_cnt && j < dst_iov_cnt && (offset || bytes); i++) { if (offset >= iov[i].iov_len) { offset -= iov[i].iov_len; continue;