From 9c05f4b6bf62a20a64a8e5735c7f3dcf0229e895 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 18 Jan 2022 12:30:11 +0100 Subject: [PATCH] lib/strutils: make sure mem2strcpy() buffer is zeroized Let's make the function robust for work with strings and uninitialized buffers. Reported-by: Sean Anderson Signed-off-by: Karel Zak --- include/strutils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/strutils.h b/include/strutils.h index f671b3ba69..8968524a61 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -106,8 +106,8 @@ static inline char *mem2strcpy(char *dest, const void *src, size_t n, size_t nma if (n + 1 > nmax) n = nmax - 1; + memset(dest, '\0', nmax); memcpy(dest, src, n); - dest[nmax-1] = '\0'; return dest; } -- 2.47.3