mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-21 02:06:37 +00:00
hostname: avoid strcpy() overlap in -d flag handling
We don't need the strcpy() anyways, just use a pointer to the hostname buffer and move it forward for `hostname -d`. Sponsored by: Klara, Inc.
This commit is contained in:
parent
43880c511c
commit
33c1e7271a
|
@ -57,7 +57,7 @@ int
|
|||
main(int argc, char *argv[])
|
||||
{
|
||||
int ch, sflag, dflag;
|
||||
char *p, hostname[MAXHOSTNAMELEN];
|
||||
char hostname[MAXHOSTNAMELEN], *hostp, *p;
|
||||
|
||||
sflag = 0;
|
||||
dflag = 0;
|
||||
|
@ -90,6 +90,7 @@ main(int argc, char *argv[])
|
|||
if (sethostname(*argv, (int)strlen(*argv)))
|
||||
err(1, "sethostname");
|
||||
} else {
|
||||
hostp = hostname;
|
||||
if (gethostname(hostname, (int)sizeof(hostname)))
|
||||
err(1, "gethostname");
|
||||
if (sflag) {
|
||||
|
@ -99,9 +100,9 @@ main(int argc, char *argv[])
|
|||
} else if (dflag) {
|
||||
p = strchr(hostname, '.');
|
||||
if (p != NULL)
|
||||
strcpy(hostname, ++p);
|
||||
hostp = p + 1;
|
||||
}
|
||||
(void)printf("%s\n", hostname);
|
||||
(void)printf("%s\n", hostp);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue