From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hvuLiGOm; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id D6DFD5A0274 for ; Thu, 09 Jul 2026 00:32:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783549934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZtcjfBRiOGQLayDUgczk/LMDXfA6QzhQUtrnfy/cneg=; b=hvuLiGOmBuP5QtZ/GioYaCxtTfbvOTowEiK1jCswg8pWqGGBQEvIhTp+Q9Jb9cAQ+AREBw o9cMyY3Gqw7iq+wNqDiAOw5tPUHQV/5SG7uyDhApX4JicDTbgU4/cs/+T8c3AtXBdBaJ1E STIGsuImewEVbqj+8ENC5BWRSRE8HmY= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-ef1b64ILO7m-WvJO6NJNXA-1; Wed, 08 Jul 2026 18:32:11 -0400 X-MC-Unique: ef1b64ILO7m-WvJO6NJNXA-1 X-Mimecast-MFC-AGG-ID: ef1b64ILO7m-WvJO6NJNXA_1783549930 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B63311956068; Wed, 8 Jul 2026 22:32:10 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.88.44]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C88A1955F75; Wed, 8 Jul 2026 22:32:09 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, david@gibson.dropbear.id.au, jmaloy@redhat.com, passt-dev@passt.top Subject: [PATCH 4/7] doc/migration: Use strncpy() for socket path and fix argv access Date: Wed, 8 Jul 2026 18:32:00 -0400 Message-ID: <20260708223203.885345-5-jmaloy@redhat.com> In-Reply-To: <20260708223203.885345-1-jmaloy@redhat.com> References: <20260708223203.885345-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Vi8Y_uNAMRBDlhKFeQY7rKlAD9rUn9NAlPIf2fpR1Zg_1783549930 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: 4SPFM3GLUCBEB3O346X7MOEQL2YFSFDV X-Message-ID-Hash: 4SPFM3GLUCBEB3O346X7MOEQL2YFSFDV X-MailFrom: jmaloy@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 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: Replace strcpy() with strncpy() when copying the helper socket path into sun_path, preventing a potential buffer overflow from a long argument. 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 --- 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..77ff8fda 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]); + strncpy(a_helper.sun_path, argv[4], sizeof(a_helper.sun_path) - 1); 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..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 = 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; } + 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 = socket(r->ai_family, SOCK_STREAM, IPPROTO_TCP); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &((int){ 1 }), sizeof(int)); -- 2.52.0