From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 1069E5A0272 for ; Wed, 20 Mar 2024 09:54:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1710924877; bh=nOGAxfRGjL4VgeLHmejc517lVg48kF+qcp5ReE0o7fc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aCvR3Q5EumchBn4cC58K7IMhu8iXXQwXpyFT1RXuubxLxn7ccgRNqRXEKePzGni2L q/2dqbmhJHEWP2xLOq4VTGFVRlahVIfT2rO8I0X6PCtSYg/spgtbS34pNhMcTPocvG E17FvNQzG1s4beRE1NH73R5yaaL4yjJGg7VTCZcetmspDt+z8nSIFw41z9/MZc2kN6 puN2VKHlgETKwip7rKUICBpxLd0W294ZOA7sL0zQaZt35ra3tK9xz8S5hUAPE4FPed 5SUH8bI2M2RDqPnKla9eapJARBgB95OKOvBfdhrFb98+VHqDuoucPcIfpxe2tZEDW6 MdF1NySQpQV7Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4V02TT3NKpz4wcQ; Wed, 20 Mar 2024 19:54:37 +1100 (AEDT) Date: Wed, 20 Mar 2024 19:53:13 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2] util: fix confusion between offset in the iovec array and in the entry Message-ID: References: <20240320084726.1851595-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TqqUGbe6PG4CY9cx" Content-Disposition: inline In-Reply-To: <20240320084726.1851595-1-lvivier@redhat.com> Message-ID-Hash: C2DUWPV4M3XAX4ARX25R7QJDLZK4SHMM X-Message-ID-Hash: C2DUWPV4M3XAX4ARX25R7QJDLZK4SHMM X-MailFrom: dgibson@gandalf.ozlabs.org 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: passt-dev@passt.top 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: --TqqUGbe6PG4CY9cx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 20, 2024 at 09:47:26AM +0100, Laurent Vivier wrote: > In write_remainder() 'skip' is the offset to start the operation from > in the iovec array. >=20 > In iov_skip_bytes(), 'skip' is also the offset in the iovec array but > 'offset' is the first unskipped byte in the iovec entry. >=20 > 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. >=20 > Fix the problem by introducing a new variable not to overwrite 'skip' > on each loop. >=20 > Fixes: 8bdb0883b441 ("util: Add write_remainder() helper") > Cc: david@gibson.dropbear.id.au > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- >=20 > Notes: > v2: > - check offset !=3D 0, not skip !=3D 0 >=20 > util.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) >=20 > 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, s= ize_t stack_size, int flags, > int write_remainder(int fd, const struct iovec *iov, int iovcnt, size_t = skip) > { > int i; > + size_t offset; > =20 > - while ((i =3D iov_skip_bytes(iov, iovcnt, skip, &skip)) < iovcnt) { > + while ((i =3D iov_skip_bytes(iov, iovcnt, skip, &offset)) < iovcnt) { > ssize_t rc; > =20 > - if (skip) { > - rc =3D write(fd, (char *)iov[i].iov_base + skip, > - iov[i].iov_len - skip); > + if (offset) { > + rc =3D write(fd, (char *)iov[i].iov_base + offset, > + iov[i].iov_len - offset); > } else { > rc =3D writev(fd, &iov[i], iovcnt - i); > } --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --TqqUGbe6PG4CY9cx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmX6o9gACgkQzQJF27ox 2GflFA/9F68oHhO3SIN0IL6RzMX0q9rq3Kuge7rpKwzY9y+Dm2KfGJGGHhHv9czd /VFFoeTR2YSMwUq5VXOySnRBkPMskV2QT9MfQjwIupvPWnYKDYaHTP4HD/DPPrQK xzgSuT+eOMVNGStoGi272wCNZxV8zUwMyEgaKEpsA51VQoi4hVwsYQUol7y0DRRF 4gL2VFfiDwncke0MlA7suNgqZlL0OPPoo5Sj3OEgyw6whh1i427DWHXMuUG2DiIZ VfvLm7GChoeTn08bVQbmfQ/3BnDwdafjjTqra7dkltSC4tmJqxojei3HmXpA0vyz WFUNeVYjP081cJrKAkqfKWCQB+2ajrD7WChjUMWwFqXVMTswedR1Ja1+Qs1qBlFZ u/KZCtc56UA8sbHrOeadPsEY8s+vpBi8BpeIDJb8o+D4Z/ceEvtSqw216t9jRcEr uPKfPYxENo0vyuxQQvAZBYW77OCphlUk+WgewAZSAHlw8MkOIzimhEghjlt39nGO m7Xtmr85AKbW0GPk70JszKB8nU3YJp/gRqmf66LCIIeRTZwCpcaJo+hq5rzXDN2u +d0MGk5jQctShUcyjzs3x0QP5Y/Vgm/BBOeYsKNfuxI1N/bsYozQ3FC3tCNpTdaz Q2zjPVHgimSYdyGJHOMRFMI8BlVQVts5x3v+sWN7swsDY6DdsoA= =avL1 -----END PGP SIGNATURE----- --TqqUGbe6PG4CY9cx--