Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Oct 2008 21:21:14 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r183989 - head/lib/libutil
Message-ID:  <200810172121.m9HLLETA098194@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Fri Oct 17 21:21:14 2008
New Revision: 183989
URL: http://svn.freebsd.org/changeset/base/183989

Log:
  Use strlcpy() when we mean it.

Modified:
  head/lib/libutil/login_times.c
  head/lib/libutil/logwtmp.c
  head/lib/libutil/realhostname.c

Modified: head/lib/libutil/login_times.c
==============================================================================
--- head/lib/libutil/login_times.c	Fri Oct 17 21:14:50 2008	(r183988)
+++ head/lib/libutil/login_times.c	Fri Oct 17 21:21:14 2008	(r183989)
@@ -72,8 +72,7 @@ parse_lt(const char * str)
 	char		buf[64];
 
 	/* Make local copy and force lowercase to simplify parsing */
-	p = strncpy(buf, str, sizeof buf);
-	buf[sizeof buf - 1] = '\0';
+	p = strlcpy(buf, str, sizeof buf);
 	for (i = 0; buf[i]; i++)
 	    buf[i] = (char)tolower(buf[i]);
 

Modified: head/lib/libutil/logwtmp.c
==============================================================================
--- head/lib/libutil/logwtmp.c	Fri Oct 17 21:14:50 2008	(r183988)
+++ head/lib/libutil/logwtmp.c	Fri Oct 17 21:21:14 2008	(r183989)
@@ -59,8 +59,7 @@ logwtmp(const char *line, const char *na
 	char   fullhost[MAXHOSTNAMELEN];
 	int fd;
 	
-	strncpy(fullhost, host, sizeof(fullhost) - 1);	
-	fullhost[sizeof(fullhost) - 1] = '\0';
+	strlcpy(fullhost, host, sizeof(fullhost));	
 	trimdomain(fullhost, UT_HOSTSIZE);
 	host = fullhost;
 

Modified: head/lib/libutil/realhostname.c
==============================================================================
--- head/lib/libutil/realhostname.c	Fri Oct 17 21:14:50 2008	(r183988)
+++ head/lib/libutil/realhostname.c	Fri Oct 17 21:21:14 2008	(r183989)
@@ -61,8 +61,7 @@ realhostname(char *host, size_t hsize, c
 		if (strlen(trimmed) <= hsize) {
 			char lookup[MAXHOSTNAMELEN];
 
-			strncpy(lookup, hp->h_name, sizeof(lookup) - 1);
-			lookup[sizeof(lookup) - 1] = '\0';
+			strlcpy(lookup, hp->h_name, sizeof(lookup));
 			hp = gethostbyname(lookup);
 			if (hp == NULL)
 				result = HOSTNAME_INVALIDNAME;



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