diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index ba79cec90b9c..bdf23bfca4ee 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -1145,8 +1145,7 @@ inetname(struct in_addr *inp) if (inp->s_addr == INADDR_ANY) strcpy(line, "*"); else if (cp) { - strncpy(line, cp, sizeof(line) - 1); - line[sizeof(line) - 1] = '\0'; + strlcpy(line, cp, sizeof(line)); } else { inp->s_addr = ntohl(inp->s_addr); #define C(x) ((u_int)((x) & 0xff)) diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 8cc26c87b6f8..01311e522bc4 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -836,8 +836,7 @@ routename(in_addr_t in) } } if (cp) { - strncpy(line, cp, sizeof(line) - 1); - line[sizeof(line) - 1] = '\0'; + strlcpy(line, cp, sizeof(line)); } else { #define C(x) ((x) & 0xff) in = ntohl(in); @@ -902,8 +901,7 @@ netname(in_addr_t in, u_long mask) } } if (cp != NULL) { - strncpy(line, cp, sizeof(line) - 1); - line[sizeof(line) - 1] = '\0'; + strlcpy(line, cp, sizeof(line)); } else { inet_ntop(AF_INET, &in, line, sizeof(line) - 1); }