From owner-dev-commits-src-all@freebsd.org Sun Oct 3 05:15:46 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CB29D6B0E96; Sun, 3 Oct 2021 05:15:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HMX9t3qmdz4RTH; Sun, 3 Oct 2021 05:15:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 415B4206A6; Sun, 3 Oct 2021 05:15:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1935FkqX008856; Sun, 3 Oct 2021 05:15:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1935Fk0F008855; Sun, 3 Oct 2021 05:15:46 GMT (envelope-from git) Date: Sun, 3 Oct 2021 05:15:46 GMT Message-Id: <202110030515.1935Fk0F008855@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 6e9b69d21955 - stable/13 - hostname: avoid strcpy() overlap in -d flag handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6e9b69d21955e348eeb0e7696a48048621a00520 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Oct 2021 05:15:46 -0000 The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=6e9b69d21955e348eeb0e7696a48048621a00520 commit 6e9b69d21955e348eeb0e7696a48048621a00520 Author: Kyle Evans AuthorDate: 2021-09-25 05:00:31 +0000 Commit: Kyle Evans CommitDate: 2021-10-03 05:14:58 +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. (cherry picked from commit 33c1e7271ac21a626829289780b88071ae46ec65) --- 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); }