Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 Aug 2015 06:11:40 +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: r287320 - head/usr.bin/tftp
Message-ID:  <201508310611.t7V6BecW073104@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Mon Aug 31 06:11:39 2015
New Revision: 287320
URL: https://svnweb.freebsd.org/changeset/base/287320

Log:
   - uri is expected to be nul-terminated (strchr used later),
     so use strlcpy instead of strncpy.
   - unroll the other two cases of strncpy+\0 to strlcpy.
  
  MFC after:	2 weeks

Modified:
  head/usr.bin/tftp/main.c

Modified: head/usr.bin/tftp/main.c
==============================================================================
--- head/usr.bin/tftp/main.c	Mon Aug 31 05:57:26 2015	(r287319)
+++ head/usr.bin/tftp/main.c	Mon Aug 31 06:11:39 2015	(r287320)
@@ -223,7 +223,7 @@ urihandling(char *URI)
 	char	line[MAXLINE];
 	int	i;
 
-	strncpy(uri, URI, ARG_MAX);
+	strlcpy(uri, URI, ARG_MAX);
 	host = uri + 7;
 
 	if ((s = strchr(host, '/')) == NULL) {
@@ -320,11 +320,10 @@ setpeer0(char *host, const char *lport)
 		/* res->ai_addr <= sizeof(peeraddr) is guaranteed */
 		memcpy(&peer_sock, res->ai_addr, res->ai_addrlen);
 		if (res->ai_canonname) {
-			(void) strncpy(hostname, res->ai_canonname,
+			(void) strlcpy(hostname, res->ai_canonname,
 				sizeof(hostname));
 		} else
-			(void) strncpy(hostname, host, sizeof(hostname));
-		hostname[sizeof(hostname)-1] = 0;
+			(void) strlcpy(hostname, host, sizeof(hostname));
 		connected = 1;
 	}
 



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