From: Karel Zak Date: Tue, 18 Jan 2022 11:30:11 +0000 (+0100) Subject: lib/strutils: make sure mem2strcpy() buffer is zeroized X-Git-Tag: v2.38-rc1~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9c05f4b6bf62a20a64a8e5735c7f3dcf0229e895;p=thirdparty%2Futil-linux.git 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 --- 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; }