From a181a9192b10317ec62d902d5c4d6d24aec591e1 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 25 Oct 2025 19:29:33 +0200 Subject: [PATCH 1/2] strxcpyx: do not access dest as an array dest is a pointer to a string, not an array. Accessing the "first element" just happens to work, but let's be more careful. --- src/basic/strxcpyx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/strxcpyx.c b/src/basic/strxcpyx.c index 9126e1dfe2..dc40d620e7 100644 --- a/src/basic/strxcpyx.c +++ b/src/basic/strxcpyx.c @@ -41,7 +41,7 @@ size_t strnpcpy_full(char **dest, size_t size, const char *src, size_t len, bool if (ret_truncated) *ret_truncated = truncated; - *dest[0] = '\0'; + (*dest)[0] = '\0'; return size; } From a169a952b66a80b47966f0773422b38feecec7b2 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 25 Oct 2025 19:18:34 +0200 Subject: [PATCH 2/2] core/exec-invoke: use strnpcpy() where appropriate --- src/core/exec-invoke.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index aaa9a0e8bd..2448baa125 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -77,6 +77,7 @@ #include "stat-util.h" #include "string-table.h" #include "strv.h" +#include "strxcpyx.h" #include "terminal-util.h" #include "user-util.h" #include "utmp-wtmp.h" @@ -1504,7 +1505,7 @@ static void rename_process_from_path(const char *path) { size_t len = strlen(buf); char comm[TASK_COMM_LEN], *p = comm; *p++ = '('; - p = mempcpy(p, buf + LESS_BY(len, (size_t) (TASK_COMM_LEN - 3)), MIN(len, (size_t) (TASK_COMM_LEN - 3))); + strnpcpy(&p, TASK_COMM_LEN - 2, buf, len); /* strnpcpy() accounts for NUL byte internally */ *p++ = ')'; *p = '\0';