From: Alejandro Colomar Date: Tue, 7 Nov 2023 17:03:08 +0000 (+0100) Subject: lib/utmp.c: Replace strncpy(3) call by ZUSTR2STP() X-Git-Tag: 4.15.0-rc1~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a1a097afa53238e727dd49236518a4c43d2f5c1;p=thirdparty%2Fshadow.git 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: f40bdfa66a3a ("libmisc: implement `get_session_host()`") Cc: Iker Pedrosa Signed-off-by: Alejandro Colomar --- diff --git a/lib/utmp.c b/lib/utmp.c index fb5c093be..906a9fac3 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -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 {