diff options
author | brian <brian@FreeBSD.org> | 1999-04-07 08:27:04 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1999-04-07 08:27:04 +0000 |
commit | 32ff8071a15df941cbe4d98c0badea284464f320 (patch) | |
tree | d7007180eea166ffba0e9933ff78193a46031507 /lib/libutil | |
parent | 5a92170186174af48c0d17f5ac102cb6d86e3083 (diff) | |
download | FreeBSD-src-32ff8071a15df941cbe4d98c0badea284464f320.zip FreeBSD-src-32ff8071a15df941cbe4d98c0badea284464f320.tar.gz |
Handle hostnames up to MAXHOSTNAMELEN-1 in length.
Use bcopy() instead of strcpy() to handle potentially
overlapping regions.
Un-obscure/complicate some code.
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/logwtmp.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index de98ee5..9759578 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; #else static const char rcsid[] = - "$Id: logwtmp.c,v 1.7 1998/10/09 00:39:09 jkh Exp $"; + "$Id: logwtmp.c,v 1.8 1998/10/09 11:24:19 jkh Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -57,15 +57,15 @@ static const char rcsid[] = void trimdomain( char * fullhost, int hostsize ) { - static char domain[MAXHOSTNAMELEN + 1]; + static char domain[MAXHOSTNAMELEN]; static int first = 1; char *s; if (first) { first = 0; - if (gethostname(domain, MAXHOSTNAMELEN) == 0 && + if (gethostname(domain, sizeof(domain) - 1) == 0 && (s = strchr(domain, '.'))) - (void) strcpy(domain, s + 1); + bcopy(s + 1, domain, strlen(s + 1) + 1); else domain[0] = 0; } @@ -93,14 +93,13 @@ logwtmp(line, name, host) { struct utmp ut; struct stat buf; - char fullhost[MAXHOSTNAMELEN + 1]; - char *whost = fullhost; + char fullhost[MAXHOSTNAMELEN]; int fd; - strncpy( whost, host, MAXHOSTNAMELEN ); -fullhost[MAXHOSTNAMELEN] = '\0'; - trimdomain( whost, UT_HOSTSIZE ); - host = whost; + strncpy(fullhost, host, sizeof(fullhost) - 1); + fullhost[sizeof(fullhost) - 1] = '\0'; + trimdomain(fullhost, UT_HOSTSIZE); + host = fullhost; if (strlen(host) > UT_HOSTSIZE) { struct hostent *hp = gethostbyname(host); |