- 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
This commit is contained in:
Xin LI 2015-08-31 06:11:39 +00:00
parent 670f01434e
commit 32e49abef0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=287320

View File

@ -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;
}