diff options
author | Brian Somers <brian@FreeBSD.org> | 2001-03-14 20:50:52 +0000 |
---|---|---|
committer | Brian Somers <brian@FreeBSD.org> | 2001-03-14 20:50:52 +0000 |
commit | ec86eec7973bda62a5ebbb21eb40f7102d84b32b (patch) | |
tree | bb833b77e848a4ebdd93a0f6f60e832ceb164b32 /lib/libutil/realhostname.c | |
parent | 3bd07cfd43ecab81686ab801a63e3ce544b1f12d (diff) | |
download | src-ec86eec7973bda62a5ebbb21eb40f7102d84b32b.tar.gz src-ec86eec7973bda62a5ebbb21eb40f7102d84b32b.zip |
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
Notes
Notes:
svn path=/head/; revision=74260
Diffstat (limited to 'lib/libutil/realhostname.c')
-rw-r--r-- | lib/libutil/realhostname.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/libutil/realhostname.c b/lib/libutil/realhostname.c index 26bd5e6174ea..7c409a8cfe70 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; |