1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-27 11:55:06 +00:00

timed(8): Use strlcpy() for bounds checking.

Prevent some theorical buffer overruns reported by Coverity.
Cleanup a use of gethostname() while here.

CID:	1006713, 1011166, 1011167, 1011168,
This commit is contained in:
Pedro F. Giffuni 2016-05-14 02:42:09 +00:00
parent 555470a31d
commit cbc796fb90
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=299709
3 changed files with 14 additions and 9 deletions

View File

@ -165,7 +165,8 @@ master(void)
* XXX check to see it is from ourself
*/
tsp_time_sec = msg->tsp_time.tv_sec;
(void)strcpy(newdate, ctime(&tsp_time_sec));
(void)strlcpy(newdate, ctime(&tsp_time_sec),
sizeof(newdate));
if (!good_host_name(msg->tsp_name)) {
syslog(LOG_NOTICE,
"attempted date change by %s to %s",
@ -183,7 +184,8 @@ master(void)
if (!fromnet || fromnet->status != MASTER)
break;
tsp_time_sec = msg->tsp_time.tv_sec;
(void)strcpy(newdate, ctime(&tsp_time_sec));
(void)strlcpy(newdate, ctime(&tsp_time_sec),
sizeof(newdate));
htp = findhost(msg->tsp_name);
if (htp == NULL) {
syslog(LOG_ERR,
@ -350,7 +352,7 @@ mchgdate(struct tsp *msg)
xmit(TSP_DATEACK, msg->tsp_seq, &from);
(void)strcpy(olddate, date());
(void)strlcpy(olddate, date(), sizeof(olddate));
/* adjust time for residence on the queue */
(void)gettimeofday(&otime, NULL);

View File

@ -254,9 +254,10 @@ slave(void)
* the following line is necessary due to syslog
* calling ctime() which clobbers the static buffer
*/
(void)strcpy(olddate, date());
(void)strlcpy(olddate, date(), sizeof(olddate));
tsp_time_sec = msg->tsp_time.tv_sec;
(void)strcpy(newdate, ctime(&tsp_time_sec));
(void)strlcpy(newdate, ctime(&tsp_time_sec),
sizeof(newdate));
if (!good_host_name(msg->tsp_name)) {
syslog(LOG_NOTICE,
@ -342,7 +343,8 @@ slave(void)
case TSP_SETDATE:
tsp_time_sec = msg->tsp_time.tv_sec;
(void)strcpy(newdate, ctime(&tsp_time_sec));
(void)strlcpy(newdate, ctime(&tsp_time_sec),
sizeof(newdate));
schgdate(msg, newdate);
break;
@ -350,7 +352,8 @@ slave(void)
if (fromnet->status != MASTER)
break;
tsp_time_sec = msg->tsp_time.tv_sec;
(void)strcpy(newdate, ctime(&tsp_time_sec));
(void)strlcpy(newdate, ctime(&tsp_time_sec),
sizeof(newdate));
htp = findhost(msg->tsp_name);
if (htp == NULL) {
syslog(LOG_WARNING,

View File

@ -196,7 +196,7 @@ main(int argc, char *argv[])
if (goodgroup != NULL || goodhosts != NULL)
Mflag = 1;
if (gethostname(hostname, sizeof(hostname) - 1) < 0)
if (gethostname(hostname, sizeof(hostname)) < 0)
err(1, "gethostname");
self.l_bak = &self;
self.l_fwd = &self;
@ -455,7 +455,7 @@ suppress(struct sockaddr_in *addr, char *name, struct netinfo *net)
if (trace)
fprintf(fd, "suppress: %s\n", name);
tgt = *addr;
(void)strcpy(tname, name);
(void)strlcpy(tname, name, sizeof(tname));
while (0 != readmsg(TSP_ANY, ANYADDR, &wait, net)) {
if (trace)