lib/utmp.c: Replace strncpy(3) call by ZUSTR2STP()
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: f40bdfa66a ("libmisc: implement `get_session_host()`")
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
751f8e055b
commit
8a1a097afa
+1
-2
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user