From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=fmzgOsKQ; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id F14CE5A026E for ; Thu, 09 Jul 2026 04:42:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1783564947; bh=eB2v9tZMIwJd5hemw8gJhHiA4pVDUfttAzds8gdmNKI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fmzgOsKQDKqhadrQbNfa3wcwF186c/DiFN9kbuwpS+9ehR1bitb42a9yUu+3NE4Xp 2INmKA5n2LPYTzpleQbqz84y/iNR2JRWBgIOZC0bmBTqkAR5eDdHK6s7rUIlC5oU+Q cSqz5FnHgBDqFz48rUjvRxjiqbkKGP+JoI0K6NkRxS6gQOXwqEgMWjMdHls20wJx2c FXB9ae/M4hh/1rD9YHuYF2Kcrs/30uyzqXtS/DJU8U3iTQQMismIpU25B1ElJ3LrfB jtul03bJ6jQVScCznh6QIMq2v3ADAb1SjP6Qk+MegVtUh9TB4lKZxGAjAMXHFaoRU3 ATe0H6ECIWIrA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gwfPv0830z4w9r; Thu, 09 Jul 2026 12:42:27 +1000 (AEST) Date: Thu, 9 Jul 2026 12:20:20 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH 4/7] doc/migration: Use strncpy() for socket path and fix argv access Message-ID: References: <20260708223203.885345-1-jmaloy@redhat.com> <20260708223203.885345-5-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="kcVH3oT2d2L8URiT" Content-Disposition: inline In-Reply-To: <20260708223203.885345-5-jmaloy@redhat.com> Message-ID-Hash: LCVYFHYV2RPT3RKLD6MULIN4ILPTFT7R X-Message-ID-Hash: LCVYFHYV2RPT3RKLD6MULIN4ILPTFT7R 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: sbrivio@redhat.com, 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: --kcVH3oT2d2L8URiT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 08, 2026 at 06:32:00PM -0400, Jon Maloy wrote: > Replace strcpy() with strncpy() when copying the helper socket path > into sun_path, preventing a potential buffer overflow from a long > argument. >=20 > In target.c, move the argc check before accessing argv[4], so we > don't dereference past the end of argv. This fixes real bugs in the examples, but.. strncpy() does not guarantee the target is \0-terminated. In this case we will end up \0-terminated, because we limit the strncpy() to exclude the last byte of the target buffer, which is initialized to all 0s. That's rather more riskly subtle than I'd like. In the passt code proper we usually use snprintf() rather than strncpy() to move an arbitrary length string into a fixed sized buffer like (including sun_path in several cases). It's strictly speaking more heavyweight than we need, but the meaning is pretty clear and it guarantees \0 termination. I'd suggest using that instead. >=20 > Signed-off-by: Jon Maloy > --- > doc/migration/source.c | 2 +- > doc/migration/target.c | 8 +++----- > 2 files changed, 4 insertions(+), 6 deletions(-) >=20 > diff --git a/doc/migration/source.c b/doc/migration/source.c > index d44ebf1f..77ff8fda 100644 > --- a/doc/migration/source.c > +++ b/doc/migration/source.c > @@ -47,7 +47,7 @@ int main(int argc, char **argv) > return -1; > } > =20 > - strcpy(a_helper.sun_path, argv[4]); > + strncpy(a_helper.sun_path, argv[4], sizeof(a_helper.sun_path) - 1); > getaddrinfo(argv[1], argv[2], &hints, &r); > =20 > /* Connect socket to server and send some data */ > diff --git a/doc/migration/target.c b/doc/migration/target.c > index f7d31083..0eb1f6ac 100644 > --- a/doc/migration/target.c > +++ b/doc/migration/target.c > @@ -38,11 +38,6 @@ int main(int argc, char **argv) > struct cmsghdr *cmsg =3D CMSG_FIRSTHDR(&msg); > struct addrinfo *r; > =20 > - (void)argc; > - > - strcpy(a_helper.sun_path, argv[4]); > - getaddrinfo(argv[1], argv[2], &hints, &r); > - > if (argc !=3D 7) { > fprintf(stderr, > "%s DST_ADDR DST_PORT SRC_PORT HELPER_PATH SSEQ RSEQ\n", > @@ -50,6 +45,9 @@ int main(int argc, char **argv) > return -1; > } > =20 > + strncpy(a_helper.sun_path, argv[4], sizeof(a_helper.sun_path) - 1); > + getaddrinfo(argv[1], argv[2], &hints, &r); > + > /* Prepare socket, bind to source port */ > s =3D socket(r->ai_family, SOCK_STREAM, IPPROTO_TCP); > setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &((int){ 1 }), sizeof(int)); > --=20 > 2.52.0 >=20 --=20 David Gibson (he or they) | 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 --kcVH3oT2d2L8URiT Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmpPBWMACgkQzQJF27ox 2GcPsQ//U2ZGTke1Vy8K24QoJqRKiGkof7zBeieXwWDqOYpTHhZlr53icA3WMrW/ xY22gZH2MxQw8aTq30SUR5aS82dyZ7KEhPwFdCpENNI5apIos7ndMQBvoaA55BXI a4q8bvEX7y1g/5LqF04cZuTAIyKFGpM8GWqblnAo+M8IRwsqAq7ZDGfyXcqo+FBj TOMGsMUsfkXuEfyB8VpmCx9OPYCOgK1ehRavz4LIvK7RHGzv4FiY6T9uWU+192Gn ZFpFLywmGyGB6ZFYngA5RBdzF2EKVueGJJAm+6u/bM/K4f+lneyK8pI7aVNFxWWt YFSUHsIyHKERtUDLsqUT1FFQn8OYiEZCzehdN6TcEB0Ime4tICSvMn+bHO1tLph3 1SO5s32A+nXeYlYvMztGwIcrT8rg2kGP9wWxbpytwndLtVwTcOVVDjsELUyUfl1B SvQLqQVYHMgB+HZCzJ4zgAvDZneAlvZaSbhta8BriuVe1L7FDhcr+AaV7D73C2eV OKEMIPJRZkH3umNYWdbipovzMs6cPayBVmvCp4PJx0PC93RKtA3uDw5LuRTS3kRM /t7mUQi7C1vH8Tg5Fu88EQ1YXG9uvTADwd+K+YzDbm1aCFCDG3g5I34UxbKoy4HI NVidtu46Lw7HdJWL8sThTITAzAgZLg+FeJtv7Yld/AkN+FDf2Ec= =dTTb -----END PGP SIGNATURE----- --kcVH3oT2d2L8URiT--