From 7cefb4bc4b1cf8c5e61a2dde8c84249712290319 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 3 Oct 2022 16:10:43 -0700 Subject: [PATCH] libfetch: Use memcpy in place of an odd strncpy. The length passed to strncpy is the length of the source string, not the destination buffer. This triggers a non-fatal warning in GCC 12. Hoewver, the code is also odd. It is really just a memcpy of the string without its nul terminator. For that use case, memcpy is clearer. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D36824 (cherry picked from commit 611cf392672cf7aa52a593412fb2537546a7d6a4) --- lib/libfetch/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c index 628ab69612f..47545e5178c 100644 --- a/lib/libfetch/common.c +++ b/lib/libfetch/common.c @@ -456,7 +456,7 @@ fetch_socks5_init(conn_t *conn, const char *host, int port, int verbose) goto fail; } *ptr++ = strlen(host); - strncpy(ptr, host, strlen(host)); + memcpy(ptr, host, strlen(host)); ptr = ptr + strlen(host); port = htons(port); -- 2.45.0