]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp.c: Replace strncpy(3) call by ZUSTR2STP()
authorAlejandro Colomar <alx@kernel.org>
Tue, 7 Nov 2023 17:03:08 +0000 (18:03 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sun, 26 Nov 2023 12:48:18 +0000 (06:48 -0600)
We were copying from a (zero-padded) fixed-width character array to a
string, but strncpy(3) is meant to do the opposite thing.  ZUSTR2STP()
is designed to be used in this case (like strncat(3)).

Fixes: f40bdfa66a3a ("libmisc: implement `get_session_host()`")
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/utmp.c

index fb5c093be4f2880fb703b44e474f4f54ffacd29a..906a9fac33231f189a26ecfaf46e72594578396a 100644 (file)
@@ -169,8 +169,7 @@ int get_session_host (char **out)
 #ifdef HAVE_STRUCT_UTMP_UT_HOST
        if ((ut != NULL) && (ut->ut_host[0] != '\0')) {
                hostname = XMALLOC(sizeof(ut->ut_host) + 1, char);
-               strncpy (hostname, ut->ut_host, sizeof (ut->ut_host));
-               hostname[sizeof (ut->ut_host)] = '\0';
+               ZUSTR2STP(hostname, ut->ut_host);
                *out = hostname;
                free (ut);
        } else {