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 B94C35A026D for ; Tue, 19 Mar 2024 11:13:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710843223; 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=9tCHE5IxOUnApSzqEnoG4YUL0w4BfuJE8hCIT/qkN+0=; b=AbHvobH73VBTC8hHrT1t/3MQiB7nBkCCdpy+ZRzfcupdxprtjyI94HrK5018pnpemc/Ycw 8m9jmMtvWpwI49F+DgV2ZGsUwoSzPIk9tk3f450N8K/d753Mpd9SysR0hvG/atwxpYY9J6 EVcYe7nQDr3FO15aKgWqlmnkwbEkldw= 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-272-P7Ae8XJfMgiaYA9EZRPeoA-1; Tue, 19 Mar 2024 06:13:42 -0400 X-MC-Unique: P7Ae8XJfMgiaYA9EZRPeoA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 0225B101A56C; Tue, 19 Mar 2024 10:13:42 +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 5FA6B2166B33; Tue, 19 Mar 2024 10:13:41 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH] util: fix confusion between offset in the iovec array and in the entry Date: Tue, 19 Mar 2024 11:13:40 +0100 Message-ID: <20240319101340.1724586-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 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: RTWIBFGANSYYG7QFEUB55P5ONLMDXHLF X-Message-ID-Hash: RTWIBFGANSYYG7QFEUB55P5ONLMDXHLF 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 --- util.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/util.c b/util.c index 3b2393d6bfa8..eee53aed811b 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); + 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