Change strcpy() to strncpy() in several places, and give gethostname()

the real buffer size.  Note that the strncpy(domain, ...) doesn't need to
be a strncpy(), since it is copying from itself to itself, but belts
and suspenders don't hurt and this is not time-critical code.

Fixes the half of PR bin/1581 that wasn't fixed in rev 1.7

Submitted by:	Karl <karl@codebase.mcs.net>
This commit is contained in:
Bill Fenner 1996-09-10 00:50:13 +00:00
parent 937dec3f90
commit 83fa788e4d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=18197

View File

@ -1,6 +1,6 @@
#ifndef lint
static char *rcsid =
"@(#)$Header: /home/ncvs/src/usr.sbin/traceroute/traceroute.c,v 1.9 1996/08/21 04:31:28 peter Exp $ (LBL)";
"@(#)$Header: /home/ncvs/src/usr.sbin/traceroute/traceroute.c,v 1.10 1996/08/21 05:59:19 peter Exp $ (LBL)";
#endif
/*
@ -427,7 +427,7 @@ main(int argc, char **argv)
to->sin_family = AF_INET;
to->sin_addr.s_addr = inet_addr(av[0]);
if (to->sin_addr.s_addr != -1) {
(void) strcpy(hnamebuf, av[0]);
(void) strncpy(hnamebuf, av[0], sizeof(hnamebuf));
hostname = hnamebuf;
} else {
hp = gethostbyname(av[0]);
@ -867,9 +867,9 @@ inetname(struct in_addr in)
if (first && !nflag) {
first = 0;
if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
if (gethostname(domain, sizeof(domain)) == 0 &&
(cp = strchr(domain, '.')))
(void) strcpy(domain, cp + 1);
(void) strncpy(domain, cp + 1, sizeof(domain));
else
domain[0] = 0;
}
@ -884,7 +884,7 @@ inetname(struct in_addr in)
}
}
if (cp)
(void) strcpy(line, cp);
(void) strncpy(line, cp, sizeof(line));
else {
in.s_addr = ntohl(in.s_addr);
#define C(x) ((x) & 0xff)