Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 May 2016 02:42:10 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r299709 - head/usr.sbin/timed/timed
Message-ID:  <201605140242.u4E2gA7g005844@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Sat May 14 02:42:09 2016
New Revision: 299709
URL: https://svnweb.freebsd.org/changeset/base/299709

Log:
  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,

Modified:
  head/usr.sbin/timed/timed/master.c
  head/usr.sbin/timed/timed/slave.c
  head/usr.sbin/timed/timed/timed.c

Modified: head/usr.sbin/timed/timed/master.c
==============================================================================
--- head/usr.sbin/timed/timed/master.c	Sat May 14 01:12:23 2016	(r299708)
+++ head/usr.sbin/timed/timed/master.c	Sat May 14 02:42:09 2016	(r299709)
@@ -165,7 +165,8 @@ loop:
 			 * 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 @@ loop:
 			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);

Modified: head/usr.sbin/timed/timed/slave.c
==============================================================================
--- head/usr.sbin/timed/timed/slave.c	Sat May 14 01:12:23 2016	(r299708)
+++ head/usr.sbin/timed/timed/slave.c	Sat May 14 02:42:09 2016	(r299709)
@@ -254,9 +254,10 @@ loop:
 			 * 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 @@ loop:
 
 		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 @@ loop:
 			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,

Modified: head/usr.sbin/timed/timed/timed.c
==============================================================================
--- head/usr.sbin/timed/timed/timed.c	Sat May 14 01:12:23 2016	(r299708)
+++ head/usr.sbin/timed/timed/timed.c	Sat May 14 02:42:09 2016	(r299709)
@@ -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 
 	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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605140242.u4E2gA7g005844>