diff --git a/lib/libutil/login_times.c b/lib/libutil/login_times.c index 10e88dd5a5f3..0c64e93a5491 100644 --- a/lib/libutil/login_times.c +++ b/lib/libutil/login_times.c @@ -72,8 +72,7 @@ parse_lt(const char * str) char buf[64]; /* Make local copy and force lowercase to simplify parsing */ - p = strncpy(buf, str, sizeof buf); - buf[sizeof buf - 1] = '\0'; + p = strlcpy(buf, str, sizeof buf); for (i = 0; buf[i]; i++) buf[i] = (char)tolower(buf[i]); diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index a7b84111a942..6ae01a7ecfe6 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -59,8 +59,7 @@ logwtmp(const char *line, const char *name, const char *host) char fullhost[MAXHOSTNAMELEN]; int fd; - strncpy(fullhost, host, sizeof(fullhost) - 1); - fullhost[sizeof(fullhost) - 1] = '\0'; + strlcpy(fullhost, host, sizeof(fullhost)); trimdomain(fullhost, UT_HOSTSIZE); host = fullhost; diff --git a/lib/libutil/realhostname.c b/lib/libutil/realhostname.c index 6a1b82f34631..146695e1c99b 100644 --- a/lib/libutil/realhostname.c +++ b/lib/libutil/realhostname.c @@ -61,8 +61,7 @@ realhostname(char *host, size_t hsize, const struct in_addr *ip) if (strlen(trimmed) <= hsize) { char lookup[MAXHOSTNAMELEN]; - strncpy(lookup, hp->h_name, sizeof(lookup) - 1); - lookup[sizeof(lookup) - 1] = '\0'; + strlcpy(lookup, hp->h_name, sizeof(lookup)); hp = gethostbyname(lookup); if (hp == NULL) result = HOSTNAME_INVALIDNAME;