aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorBrian Somers <brian@FreeBSD.org>1999-04-07 08:27:04 +0000
committerBrian Somers <brian@FreeBSD.org>1999-04-07 08:27:04 +0000
commit5b3f0a74e15f741303eb4c823555de3464f8ef7c (patch)
treede672ea252192f36d59892a6c8fc1cfdb644574a /lib/libutil
parentbc19c8517d1688a79cdce7e472db43fec238045b (diff)
downloadsrc-5b3f0a74e15f741303eb4c823555de3464f8ef7c.tar.gz
src-5b3f0a74e15f741303eb4c823555de3464f8ef7c.zip
Handle hostnames up to MAXHOSTNAMELEN-1 in length.
Use bcopy() instead of strcpy() to handle potentially overlapping regions. Un-obscure/complicate some code.
Notes
Notes: svn path=/head/; revision=45421
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/logwtmp.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c
index de98ee59be60..9759578356ed 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);