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=OEuIgS3c; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 68CCD5A0269 for ; Fri, 10 Jul 2026 03:37:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1783647461; bh=M3qTHR3ak58aIv91KN6huH9/Z+kybQHE4VBKULpBYPE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OEuIgS3cXQWMk0V6oLFEGHfJX0JUpOvtpawebt3Ioefoa9QCZk26hNtnVUjRT0ppu Xznbt+i2OZCyhwsanU9djDLiYSZFGG+r5kj/yzC9BmPXrM8RJDwjomwB8VT83nXCU5 sfr0lx/jDpJXcmX18/xJ/vHuzopAKSBBXgE+47sRpoOsedFikvL47MvlU6JbIj4Uj4 dLeigFav5M1ebGz89+BRzwHODDCom5rkFHzAXjzY7PR7z7+z4bga8aK9i7qZzX9MYs JJqZA2YYGPz4T0acRMf/evqyabdQr884pMOv0Q44FE/eWB9XkqGi7MYH2iJkosJqRD t63pcuYJeyJlQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gxDwj17WQz58dt; Fri, 10 Jul 2026 11:37:41 +1000 (AEST) Date: Fri, 10 Jul 2026 11:37:22 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v2 4/6] doc/migration: Use snprintf() for socket path and fix argv access Message-ID: References: <20260709215656.1351549-1-jmaloy@redhat.com> <20260709215656.1351549-5-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="033zi9RrkfzJprkf" Content-Disposition: inline In-Reply-To: <20260709215656.1351549-5-jmaloy@redhat.com> Message-ID-Hash: BQLWXUDOJ23VVQNZCR4G5DFUN4G5S5LT X-Message-ID-Hash: BQLWXUDOJ23VVQNZCR4G5DFUN4G5S5LT 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: --033zi9RrkfzJprkf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 09, 2026 at 05:56:54PM -0400, Jon Maloy wrote: > Replace strcpy() with snprintf() when copying the helper socket path > into sun_path, preventing a potential buffer overflow from a long > argument and guaranteeing null-termination. >=20 > In target.c, move the argc check before accessing argv[4], so we > don't dereference past the end of argv. >=20 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson Although... it wouldn't surprise me if some static checker now complains about not testing the return value from snprintf(). >=20 > --- > v2: Use snprintf() instead of strncpy() for clarity and > guaranteed null-termination, as suggested by David Gibson > --- > 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..8aad0259 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]); > + snprintf(a_helper.sun_path, sizeof(a_helper.sun_path), "%s", argv[4]); > 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..e2469837 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 > + snprintf(a_helper.sun_path, sizeof(a_helper.sun_path), "%s", argv[4]); > + 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 --033zi9RrkfzJprkf Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmpQTMgACgkQzQJF27ox 2GeOjg/+Os7piOPIllU8K83Q24tUB1o+nCUpCbxJPQXv5srw1HRQpdRmhyhwkrNL yKwsMW5XDd5zDL1R9cwiq1+XG7Tm4BuKcU7UdRLmwfqvkE2qJqH6i3PHPy8a3/JQ BGrZjcYYkfP61GTusCZsFPx5aH3+cT2cONZM4+ySS8j4akc5CIjsp3oOVW3cMqyZ FFvHYUd56qe6tAA15hVeb+T24gZHz4t84h7xECHUro5iM8lGGblSqm3d8MDVhJS0 aEMFRrG6eZyeKJD7wMiZxe8TJRBXlrnAFltZeIBD2naVpHu4uQ5tytPXwrfktfmS cxt41ySOxpB/mLI3yoDdTfrHtnGz9kyBkr+99kEM7KbNxlSFn7xNUOuQqV+txpuG QwiferFFpmkq6YwoWHBrQ4O/AeToDHUXtkOWlhljSsm6hxTzfnT8UCOruztC5nre /3LLGczSfsN3mOkxjC+hbdUV5/noXNExFRM/JDqFGVWQJRWTqXvMEw+Uvl+HAtlJ BMScLBqKTxlxFTQtBbO+PCPx/mMFHYmxpsVqUkvOPQhc9CMMTVAKA0rg4qYavNNM RLdrK5iIix352+lx8n7OoLsqBwonk/fhtMibnNH1oJ0BL417qCFZcGM7gNR/LI9B tdbXcvNSEd3kAkLd5tn16k+s09sPBP7nnSG0Rn8N9S+sUMV94lg= =1Ff/ -----END PGP SIGNATURE----- --033zi9RrkfzJprkf--