From: Jon Maloy <jmaloy@redhat.com>
To: sbrivio@redhat.com, david@gibson.dropbear.id.au,
jmaloy@redhat.com, passt-dev@passt.top
Subject: [PATCH v2 4/6] doc/migration: Use snprintf() for socket path and fix argv access
Date: Thu, 9 Jul 2026 17:56:54 -0400 [thread overview]
Message-ID: <20260709215656.1351549-5-jmaloy@redhat.com> (raw)
In-Reply-To: <20260709215656.1351549-1-jmaloy@redhat.com>
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.
In target.c, move the argc check before accessing argv[4], so we
don't dereference past the end of argv.
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
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(-)
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;
}
- 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);
/* 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 = CMSG_FIRSTHDR(&msg);
struct addrinfo *r;
- (void)argc;
-
- strcpy(a_helper.sun_path, argv[4]);
- getaddrinfo(argv[1], argv[2], &hints, &r);
-
if (argc != 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;
}
+ 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 = socket(r->ai_family, SOCK_STREAM, IPPROTO_TCP);
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &((int){ 1 }), sizeof(int));
--
2.52.0
next prev parent reply other threads:[~2026-07-09 21:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 21:56 [PATCH v2 0/6] Fix issues and false positives from static analysis Jon Maloy
2026-07-09 21:56 ` [PATCH v2 1/6] passt: Initialise listening socket fds to -1 Jon Maloy
2026-07-09 21:56 ` [PATCH v2 2/6] udp_vu: Check iov_tail_clone() return before assigning to msg_iovlen Jon Maloy
2026-07-10 1:32 ` David Gibson
2026-07-09 21:56 ` [PATCH v2 3/6] tap: Guard IPv6 tail size subtraction against underflow Jon Maloy
2026-07-10 1:36 ` David Gibson
2026-07-09 21:56 ` Jon Maloy [this message]
2026-07-10 1:37 ` [PATCH v2 4/6] doc/migration: Use snprintf() for socket path and fix argv access David Gibson
2026-07-09 21:56 ` [PATCH v2 5/6] doc/migration: Fix buffer type mismatch in recv() call Jon Maloy
2026-07-09 21:56 ` [PATCH v2 6/6] doc/platform-requirements: Close leaked sockets in test_close_dup() Jon Maloy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260709215656.1351549-5-jmaloy@redhat.com \
--to=jmaloy@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).