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>
#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 {