From owner-svn-src-all@freebsd.org Sat May 14 02:42:11 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3D004B3A371; Sat, 14 May 2016 02:42:11 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1306B1E00; Sat, 14 May 2016 02:42:11 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4E2gAfS005848; Sat, 14 May 2016 02:42:10 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4E2gA7g005844; Sat, 14 May 2016 02:42:10 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201605140242.u4E2gA7g005844@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Sat, 14 May 2016 02:42:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299709 - head/usr.sbin/timed/timed X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 May 2016 02:42:11 -0000 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)