MAXHOSTNAMELEN includes space for the NUL
Don't read past the end of the host passed to realhostname() Not objected to by: freebsd-audit Interface disliked by: imp
This commit is contained in:
parent
3bd07cfd43
commit
ec86eec797
@ -52,7 +52,7 @@ struct sockinet {
|
||||
int
|
||||
realhostname(char *host, size_t hsize, const struct in_addr *ip)
|
||||
{
|
||||
char trimmed[MAXHOSTNAMELEN+1];
|
||||
char trimmed[MAXHOSTNAMELEN];
|
||||
int result;
|
||||
struct hostent *hp;
|
||||
|
||||
@ -136,15 +136,15 @@ realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen)
|
||||
freeaddrinfo(ores);
|
||||
goto numeric;
|
||||
}
|
||||
strncpy(buf, ores->ai_canonname,
|
||||
strlcpy(buf, ores->ai_canonname,
|
||||
sizeof(buf));
|
||||
trimdomain(buf, hsize);
|
||||
strncpy(host, buf, hsize);
|
||||
if (strlen(host) > hsize &&
|
||||
if (strlen(buf) > hsize &&
|
||||
addr->sa_family == AF_INET) {
|
||||
freeaddrinfo(ores);
|
||||
goto numeric;
|
||||
}
|
||||
strncpy(host, buf, hsize);
|
||||
break;
|
||||
}
|
||||
((struct sockinet *)addr)->si_port = port;
|
||||
|
Loading…
Reference in New Issue
Block a user