From nobody Sat Feb 25 18:43:00 2023 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 4PPFxw5YHMz3tlH4; Sat, 25 Feb 2023 18:43:00 +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 4PPFxw54dHz43ZG; Sat, 25 Feb 2023 18:43:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677350580; 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=s2GDjrD8cP0IsdB0t+LwsUuZnmWdsK3+EE4SyCYguFQ=; b=CakSOyuab/dP9f1+tlQ1CpYcGbrFZqEtLuUl2btsJL/+efG0Pu5mRdEA4B284l+mwNBUC7 LyTTVBi2h/YCxsCOxc06kelXtPg+l8q5c/LGYVdfV8gPXoWK4njYFEBdy9nVWCzpl3XLqU G1HjPNZovirrg8oWsAFL/E+VlBYDR446agv1yIHCB3b6UDXNaU9uBw5cSPcK8YOWjEeqEw WDehy+m5D8xwWJ/DFm0WgisXMEIEn5gnjMp/xw+HNPBOthb8u/IK+HPHnGCme2EjnkbGgl 5xvQyJHSrMgoTDYicTfkd0NdSj4PLBT15LVmCwVmfhTuoKVNR3kfCyA0tM+3fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677350580; 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=s2GDjrD8cP0IsdB0t+LwsUuZnmWdsK3+EE4SyCYguFQ=; b=tF6E6V+sOd55asWjmD97Wmdlqzv4lxGUVpdpjd00DqKRsL6QbTYRzEEL2iXKqWjqIpRNXx ZN3nnemyt+oxAmL3KKHpy+uDNaL8dI7CM8yk5Rq1BARsejqRQB+TtxXxl12tmjMlKr3uUY iyhAK9d1r360GWfa4ZJs4toCEBrRq3vb+MztU7Kzn2DaeF9GZ7c/UwwKd9/9lGlNEYVrS+ 83C5JeV1yMVL5Q/xFlsln17DYnHtVAUO+X+NuEP9gEiaIXrPU5yVSvew+JJMUdACP4+ORS tUGNpLJkOOuwDOb1KVJ8QZh7vzDgMXrVSGRcyf42PAXhemtrcgzj1j6MOxiUGA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677350580; a=rsa-sha256; cv=none; b=UTDTvRZA0qDNLGX1ZtlS7Cumn4+dd/aqUAwS/qLpPEEzuYKSSLRP4BwoOtyMBGntKt5Rny WZrxGrQimn15A9s/AnSqKAxEPlaSl9zwublBzMckAkcZT4uXObWNowRayk8gFEjMtI6VFD QcZSDXe1p+g4JMnTQj+pXlxNKNgSzPRM2fbHcgcI/f/xb+2SMK+Sj5e5w5vgq7vHj91TRC z50qvXH0kScoB6yoB16XjCaZozPHCeT+Lp67jG422ohEM7FEUYihEdR5dJLthvGtoLN+Xu 1nhgbIo95GFzlfXzPtpZ37bbZY1lTr6uiEYi1wYoR8UKrUfAGkE2kXICW/O47w== 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 4PPFxw47M7zFdN; Sat, 25 Feb 2023 18:43:00 +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 31PIh0WT082241; Sat, 25 Feb 2023 18:43:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31PIh0HS082240; Sat, 25 Feb 2023 18:43:00 GMT (envelope-from git) Date: Sat, 25 Feb 2023 18:43:00 GMT Message-Id: <202302251843.31PIh0HS082240@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Wing Subject: git: c5f019807059 - main - stand: fix buffer overflow in getrootmount() 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c5f01980705930bf46059a004e20e010d8e21dfa Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rew: URL: https://cgit.FreeBSD.org/src/commit/?id=c5f01980705930bf46059a004e20e010d8e21dfa commit c5f01980705930bf46059a004e20e010d8e21dfa Author: Robert Wing AuthorDate: 2023-02-25 09:37:32 +0000 Commit: Robert Wing CommitDate: 2023-02-25 09:37:32 +0000 stand: fix buffer overflow in getrootmount() Reviewed by: imp, allanjude Sponsored By: Beckhoff Automation GmbH & Co. KG Sponsored By: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38734 --- stand/common/boot.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stand/common/boot.c b/stand/common/boot.c index 06f604f595df..3ec827617d56 100644 --- a/stand/common/boot.c +++ b/stand/common/boot.c @@ -32,8 +32,9 @@ __FBSDID("$FreeBSD$"); */ #include -#include #include +#include +#include #include #include "bootstrap.h" @@ -321,14 +322,14 @@ getbootfile(int try) int getrootmount(char *rootdev) { - char lbuf[128], *cp, *ep, *dev, *fstyp, *options; + char lbuf[KENV_MVALLEN], *cp, *ep, *dev, *fstyp, *options; int fd, error; if (getenv("vfs.root.mountfrom") != NULL) return(0); error = 1; - sprintf(lbuf, "%s/etc/fstab", rootdev); + snprintf(lbuf, sizeof(lbuf), "%s/etc/fstab", rootdev); if ((fd = open(lbuf, O_RDONLY)) < 0) goto notfound; @@ -382,7 +383,7 @@ getrootmount(char *rootdev) *cp = 0; options = strdup(ep); /* Build the : and save it in vfs.root.mountfrom */ - sprintf(lbuf, "%s:%s", fstyp, dev); + snprintf(lbuf, sizeof(lbuf), "%s:%s", fstyp, dev); setenv("vfs.root.mountfrom", lbuf, 0); /* Don't override vfs.root.mountfrom.options if it is already set */