summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2001-03-14 20:50:52 +0000
committerbrian <brian@FreeBSD.org>2001-03-14 20:50:52 +0000
commitfcbc4cffa6d09c75f5ee941cb1832a175599e1d2 (patch)
tree07fa30f9ac32d2cfa0d92cb6afd34d2acffac227 /lib
parent71a0040fe08bf4a0d07d5d4c75094e94b5715b58 (diff)
downloadFreeBSD-src-fcbc4cffa6d09c75f5ee941cb1832a175599e1d2.zip
FreeBSD-src-fcbc4cffa6d09c75f5ee941cb1832a175599e1d2.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/realhostname.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/libutil/realhostname.c b/lib/libutil/realhostname.c
index 26bd5e6..7c409a8 100644
--- a/lib/libutil/realhostname.c
+++ b/lib/libutil/realhostname.c
@@ -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;
OpenPOWER on IntegriCloud