Use strlcpy in place of strncpy + setting the last character NUL. To

be safe, memset the entire msg to '0'.
This commit is contained in:
Warner Losh 2006-08-20 06:31:24 +00:00
parent be57e3dd35
commit c608a9a591
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=161469

View File

@ -108,14 +108,14 @@ netsettime(time_t tval)
warnx("all ports in use"); warnx("all ports in use");
goto bad; goto bad;
} }
memset(&msg, 0, sizeof(msg));
msg.tsp_type = TSP_SETDATE; msg.tsp_type = TSP_SETDATE;
msg.tsp_vers = TSPVERSION; msg.tsp_vers = TSPVERSION;
if (gethostname(hostname, sizeof(hostname))) { if (gethostname(hostname, sizeof(hostname))) {
warn("gethostname"); warn("gethostname");
goto bad; goto bad;
} }
(void)strncpy(msg.tsp_name, hostname, sizeof(msg.tsp_name) - 1); (void)strlcpy(msg.tsp_name, hostname, sizeof(msg.tsp_name));
msg.tsp_name[sizeof(msg.tsp_name) - 1] = '\0';
msg.tsp_seq = htons((u_short)0); msg.tsp_seq = htons((u_short)0);
msg.tsp_time.tv_sec = htonl((u_long)tval); msg.tsp_time.tv_sec = htonl((u_long)tval);
msg.tsp_time.tv_usec = htonl((u_long)0); msg.tsp_time.tv_usec = htonl((u_long)0);