Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Sep 2021 05:04:58 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 33c1e7271ac2 - main - hostname: avoid strcpy() overlap in -d flag handling
Message-ID:  <202109250504.18P54waG030560@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=33c1e7271ac21a626829289780b88071ae46ec65

commit 33c1e7271ac21a626829289780b88071ae46ec65
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2021-09-25 05:00:31 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2021-09-25 05:03:50 +0000

    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.
---
 bin/hostname/hostname.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/bin/hostname/hostname.c b/bin/hostname/hostname.c
index d5cc6b1cfff2..3dbafa9d3566 100644
--- a/bin/hostname/hostname.c
+++ b/bin/hostname/hostname.c
@@ -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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109250504.18P54waG030560>