diff --git a/bin/date/netdate.c b/bin/date/netdate.c index 77e07882f19c..b8441068eadf 100644 --- a/bin/date/netdate.c +++ b/bin/date/netdate.c @@ -108,14 +108,14 @@ netsettime(time_t tval) warnx("all ports in use"); goto bad; } + memset(&msg, 0, sizeof(msg)); msg.tsp_type = TSP_SETDATE; msg.tsp_vers = TSPVERSION; if (gethostname(hostname, sizeof(hostname))) { warn("gethostname"); goto bad; } - (void)strncpy(msg.tsp_name, hostname, sizeof(msg.tsp_name) - 1); - msg.tsp_name[sizeof(msg.tsp_name) - 1] = '\0'; + (void)strlcpy(msg.tsp_name, hostname, sizeof(msg.tsp_name)); msg.tsp_seq = htons((u_short)0); msg.tsp_time.tv_sec = htonl((u_long)tval); msg.tsp_time.tv_usec = htonl((u_long)0);