]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/strutils: make sure mem2strcpy() buffer is zeroized
authorKarel Zak <kzak@redhat.com>
Tue, 18 Jan 2022 11:30:11 +0000 (12:30 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 18 Jan 2022 11:30:11 +0000 (12:30 +0100)
Let's make the function robust for work with strings and uninitialized
buffers.

Reported-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/strutils.h

index f671b3ba6977a74175cbec6e2bc2dfe7ae67c0e0..8968524a61d378855844400a6c62d39b68f2e248 100644 (file)
@@ -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;
 }