From nobody Thu Aug 08 20:07:06 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WfykL5pKtz5S94p; Thu, 08 Aug 2024 20:07:06 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WfykL4rtpz4pmf; Thu, 8 Aug 2024 20:07:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723147626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/Fyb6QDu9yfB0wI8Izj1gfP5F7rs20ERw4iufsbn8gA=; b=sYC5fiz74nkC+fV8YNETHuVnJJTJLNEAscqCPQGPLqR/w3LYJnAQFawU5CfMIGWU2b9BOs 1WQBpJakKDebY8Itl3Fcbb07fLwYoWgqLv5AGtBRGKRS6HZQ5aOG5ZtFDhBV2CD5/5SLwA vkyunKMX2NQtm2C1aOoWCWc5abIMpH9tQFi7eCTYt2lktJRVUNZd/mSEfYFyiC7MxjerIK 5NU7e7nGC86JOhPvyCq6el//hDkJlNX2edFhodEkcU+2oilTZ5YKzkYCUdngsyTQX6nW7s 2wmhgbqVWsZVjBXUBLRmsObwS0bE7qmWmx1397mzuNVd6COR4magBH1z4177eQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1723147626; a=rsa-sha256; cv=none; b=B522ZpJdXx9aom9Fv2U5oEDtP8laLcQ9YVWz0ZoGRgnI8e450fG9iuzTKEuftndjossT8U 5FhjAAICSQE6myQxufT/rPL/DACl/WQukgmfA19H171Jkvu/Vu3Z+NSeJOtpny1dIpwEY3 WE2Qfvsf2Ocj5URC6UzTXe49NYEPncfwquudsqP9VY4VC5ywbqKhdn+OwFKw17M6yWjIKA HQ7PhhPt6Jxe5W7EpHBuS40dmmXbTfhF0/RLgA8P8MV373nMPKS4WYvjzTHyGkmUqJI3aZ 6mQK54LuLcEObSLExqAcaGZvFA0aGshDEoT5ttOJUOllL14gA/wBW6OXderRow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723147626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/Fyb6QDu9yfB0wI8Izj1gfP5F7rs20ERw4iufsbn8gA=; b=yqbNbAgzVqDKuIrYxF+qf7U95CaGBcUaiJT3Qk7a5YbwwvxTRj6lV5PxoFNnuAHGIN46FY ID5OOEw/RqzRhZ0HEtDLYe3I9zy9c3YdIeUGNTdVzrCTBPC2S+CYMhY6FKA0NBmKa3cCgA mFyXLHnE+VPZjRKKGJ4VYGV42Jd+5/lFcyMc08jDczZwBO15u6Dkd+LXizB5bRcwbrGjII aHadYbAMfZvWFzWl7vHu21rXL46lbwDM9JsZqVpaUDEe8eTYomqtIRfSP6+yACb3DgCD5h hD7hq8c/9fko+2B8APHt9esVKfY58fUkE+c+Tkpznqfbw/uXpNV0SLnfAejfXw== 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 4WfykL3yd6zn7V; Thu, 8 Aug 2024 20:07:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 478K767I017317; Thu, 8 Aug 2024 20:07:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 478K76DW017314; Thu, 8 Aug 2024 20:07:06 GMT (envelope-from git) Date: Thu, 8 Aug 2024 20:07:06 GMT Message-Id: <202408082007.478K76DW017314@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: 781bc1a69fab - stable/13 - route: avoid overlapping strcpy List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org 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: 781bc1a69fab3ccb93deab611d19be18d093ca26 Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=781bc1a69fab3ccb93deab611d19be18d093ca26 commit 781bc1a69fab3ccb93deab611d19be18d093ca26 Author: Kyle Evans AuthorDate: 2024-07-23 20:25:46 +0000 Commit: Kyle Evans CommitDate: 2024-08-08 20:00:37 +0000 route: avoid overlapping strcpy Passing overlapping buffers to strcpy yields an undefined result, so let's avoid it. The copy doesn't really need to happen anyways, we can just point to the domain part of the hostname. This was discovered with _FORTIFY_SOURCE. Sponsored by: Klara, Inc. Sponsored by: Stormshield Reviewed by: allanjude, emaste, imp, melifaro (all previous version) (cherry picked from commit 158f319428c10143ce2ffe766416207c75578931) --- sbin/route/route.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index c48a39b490dd..d82ab2c054ae 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -108,8 +108,8 @@ static u_long rtm_inits; static uid_t uid; static int defaultfib; static int numfibs; -static char domain[MAXHOSTNAMELEN + 1]; -static bool domain_initialized; +static char domain_storage[MAXHOSTNAMELEN + 1]; +static const char *domain; static int rtm_seq; static char rt_line[NI_MAXHOST]; static char net_line[MAXHOSTNAMELEN + 1]; @@ -563,14 +563,16 @@ routename(struct sockaddr *sa) const char *cp; int n; - if (!domain_initialized) { - domain_initialized = true; - if (gethostname(domain, MAXHOSTNAMELEN) == 0 && - (cp = strchr(domain, '.'))) { - domain[MAXHOSTNAMELEN] = '\0'; - (void)strcpy(domain, cp + 1); - } else - domain[0] = '\0'; + if (domain == NULL) { + if (gethostname(domain_storage, + sizeof(domain_storage) - 1) == 0 && + (cp = strchr(domain_storage, '.')) != NULL) { + domain_storage[sizeof(domain_storage) - 1] = '\0'; + domain = cp + 1; + } else { + domain_storage[0] = '\0'; + domain = domain_storage; + } } /* If the address is zero-filled, use "default". */