From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 1BC235A0272 for ; Wed, 20 Mar 2024 09:47:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710924450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eb2jHwrWA8gjybG8rcY8U2R5HZeGUo6p4TLj5aJm7wI=; b=V+2Enh5WpwLcYULBxQTEdRYLEzCD5cbe4Y6iOdfUtoJQiwCadi+XoEMpJDELdNeBbij3rW AhGtpT9nVnZMLMg7SiqQipdjheYvh6ALBbYcZ9dNsksZxALtUpRafHGewvdwv8WKQyNyzP 7Uq+lHZYldx6H7XIVvljBVCQRmxgGAo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-o6dA803BMGyLud__fkPAlg-1; Wed, 20 Mar 2024 04:47:28 -0400 X-MC-Unique: o6dA803BMGyLud__fkPAlg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DCEF86C04F; Wed, 20 Mar 2024 08:47:27 +0000 (UTC) Received: from virtlab218.virt.lab.eng.bos.redhat.com (virtlab218.virt.lab.eng.bos.redhat.com [10.19.152.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61E6B3C21; Wed, 20 Mar 2024 08:47:27 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2] util: fix confusion between offset in the iovec array and in the entry Date: Wed, 20 Mar 2024 09:47:26 +0100 Message-ID: <20240320084726.1851595-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: WIF7CLVJQ337YWLILVBV65J4RLP64XB3 X-Message-ID-Hash: WIF7CLVJQ337YWLILVBV65J4RLP64XB3 X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Laurent Vivier , david@gibson.dropbear.id.au X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In write_remainder() 'skip' is the offset to start the operation from in the iovec array. In iov_skip_bytes(), 'skip' is also the offset in the iovec array but 'offset' is the first unskipped byte in the iovec entry. As write_remainder() uses 'skip' for both, 'skip' is reset to the first unskipped byte in the iovec entry rather to staying the first unskipped byte in the iovec array. Fix the problem by introducing a new variable not to overwrite 'skip' on each loop. Fixes: 8bdb0883b441 ("util: Add write_remainder() helper") Cc: david@gibson.dropbear.id.au Signed-off-by: Laurent Vivier --- Notes: v2: - check offset != 0, not skip != 0 util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/util.c b/util.c index 3b2393d6bfa8..849fa7f608c6 100644 --- a/util.c +++ b/util.c @@ -533,13 +533,14 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags, int write_remainder(int fd, const struct iovec *iov, int iovcnt, size_t skip) { int i; + size_t offset; - while ((i = iov_skip_bytes(iov, iovcnt, skip, &skip)) < iovcnt) { + while ((i = iov_skip_bytes(iov, iovcnt, skip, &offset)) < iovcnt) { ssize_t rc; - if (skip) { - rc = write(fd, (char *)iov[i].iov_base + skip, - iov[i].iov_len - skip); + if (offset) { + rc = write(fd, (char *)iov[i].iov_base + offset, + iov[i].iov_len - offset); } else { rc = writev(fd, &iov[i], iovcnt - i); } -- 2.42.0