From nobody Mon Dec 30 00:41:22 2024 X-Original-To: dev-commits-src-main@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 4YLy2p6S4Xz5j590; Mon, 30 Dec 2024 00:41:22 +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 4YLy2p4hPwz4nf4; Mon, 30 Dec 2024 00:41:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735519282; 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=TB3k9eOMTFW6o413ZUVr3tmxqhC3P0pZuGakuuey9iE=; b=bTHS6WIZS2trtidOU2I/lIx9N0mzJqPXbIW4nTPMzqvd+KZwei01psaRloZu2VnmhQzQMy dLMfMgXnqPsX7XuX/Jbt7tVn769s33S1KvMeJgZvI6ZJqvnTMMpXCW6HzfmX9JCrlmC956 qY9Zlhh7iUW0lRT7lss3ogyOuFEOO1Iq0zJKvODvgvWo9uH3cYJ5MvddW0I2+ApcjSwIcO IEQfAdoXByMyyEfI6uh8gHphR13NoFbtWhi9VwAkDoGl963yLIqFtx9xDSkbHiYRurbG4W JJOFiJA+TXXd5qSQ/ksaOhEoyPKCXc2+PjzF6tWjT22gf8LG1emJimCQXoLTaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735519282; 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=TB3k9eOMTFW6o413ZUVr3tmxqhC3P0pZuGakuuey9iE=; b=NRFZYFmanefAgFV1c3Gj6DfvfyzbZ84YG3A0jpNOYZLnnATeKJdFHqSR3a7KtJDNYgYBpb 9q4luMqHc9e+fJR1A9jpr2VAAnzUeSVaUbfUF9cEioFQ7J0nd3LhX98bfhV0gcygYpy9/5 BnHeuHMGs68VQVVG4joJhZ94nxTVHFsFFb5vFZEu2lF+phR+aZYc0Jn2KwR33OpYEIIH84 YLu7++a8dLQdp0jEJdo98go9etkl0LlNOcPh6vTi3uiXjHicnGxeVOJ+VW/Q9yxIRkaNXx F8OwwgDV9BI3EgrM2V69uxAC80hf9BH4LOpORlCgSVeh87spuoSuDqHcmGM0aQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735519282; a=rsa-sha256; cv=none; b=S5bi2CjPRnoosEGKJlAKM51GsWdBLJSNX1RLO135GPeUPCIo9GDdAlViKQ45lwd8IW7VPQ YfPjd9DJYefmLFBjowGXL5nc8C30sVmd9P76JI3VbDSzbK7x9kgXTD/qSnZhKZQW0UvrMu A1K/idSVi/uonkdD/7jYpUJ/37D7Z63EQkyu4P/jjUTTi4KrheZLZgV6xdkLeWURObbL+W fgqokmra18qBptzIES3XcsFeQimmfE4hk+4uaaCXZ9zHqng/f7vRPLyGD1+2gNFRE/Z/4N Urx3jmnsaqCsc0ArUMe9vXT9pDeSjy7r/6LV/pZfzF8CCXtI20AHWxM3289ocw== 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 4YLy2p4Hk4zY7J; Mon, 30 Dec 2024 00:41:22 +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 4BU0fMnB076874; Mon, 30 Dec 2024 00:41:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BU0fMO3076871; Mon, 30 Dec 2024 00:41:22 GMT (envelope-from git) Date: Mon, 30 Dec 2024 00:41:22 GMT Message-Id: <202412300041.4BU0fMO3076871@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Jason A. Harmening" Subject: git: a314c60625af - main - mount(8): Avoid truncation when fstab-formatting unionfs mount info List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jah X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a314c60625af1829b7e12c3a4cedb74d7f69d074 Auto-Submitted: auto-generated The branch main has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=a314c60625af1829b7e12c3a4cedb74d7f69d074 commit a314c60625af1829b7e12c3a4cedb74d7f69d074 Author: Jason A. Harmening AuthorDate: 2024-12-22 06:36:30 +0000 Commit: Jason A. Harmening CommitDate: 2024-12-30 00:39:49 +0000 mount(8): Avoid truncation when fstab-formatting unionfs mount info When displaying unionfs mounts in fstab format (`mount -p`), mount(8) currently uses strlcpy to remove the disposition prefix from the mount name returned by getmntinfo(3). But strlcpy, like strcpy before it, does not guarantee correct behavior if the source and destination buffers overlap. Just offset the buffer and avoid the destructive copy in the first place. PR: 283420 Reviewed by: imp (previous version), olce MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D48177 --- sbin/mount/mount.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index 1b8eceb9a6ed..cf603a63e394 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -892,9 +892,11 @@ void putfsent(struct statfs *ent) { struct fstab *fst; + const char *mntfromname; char *opts, *rw; int l; + mntfromname = ent->f_mntfromname; opts = NULL; /* flags2opts() doesn't return the "rw" option. */ if ((ent->f_flags & MNT_RDONLY) != 0) @@ -905,16 +907,14 @@ putfsent(struct statfs *ent) opts = flags2opts(ent->f_flags); opts = catopt(rw, opts); - if (strncmp(ent->f_mntfromname, "", 7) == 0 || - strncmp(ent->f_mntfromname, "", 7) == 0) { - strlcpy(ent->f_mntfromname, - (strnstr(ent->f_mntfromname, ":", 8) +1), - sizeof(ent->f_mntfromname)); + if (strncmp(mntfromname, ":", 8) == 0 || + strncmp(mntfromname, ":", 8) == 0) { + mntfromname += 8; } - l = strlen(ent->f_mntfromname); + l = strlen(mntfromname); xo_emit("{:device}{P:/%s}{P:/%s}{P:/%s}", - ent->f_mntfromname, + mntfromname, l < 8 ? "\t" : "", l < 16 ? "\t" : "", l < 24 ? "\t" : " "); @@ -930,7 +930,7 @@ putfsent(struct statfs *ent) l < 8 ? "\t" : " "); free(opts); - if ((fst = getfsspec(ent->f_mntfromname))) + if ((fst = getfsspec(mntfromname))) xo_emit("{P:\t}{n:dump/%u}{P: }{n:pass/%u}\n", fst->fs_freq, fst->fs_passno); else if ((fst = getfsfile(ent->f_mntonname)))