aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Harmening <jah@FreeBSD.org>2024-12-22 06:36:30 +0000
committerJason A. Harmening <jah@FreeBSD.org>2025-01-09 06:10:00 +0000
commit6584e5a1c54ff24ed7c9eb80a884b4e7f54e7288 (patch)
tree41edbc425d2dbf36d4ff0f18d2054c7bef6e4b46
parent96ef85cc51ba2eccc6a043227aa993180e5a0473 (diff)
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 Differential Revision: https://reviews.freebsd.org/D48177 (cherry picked from commit a314c60625af1829b7e12c3a4cedb74d7f69d074)
-rw-r--r--sbin/mount/mount.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index 2fcc94e40818..bb84d9696d12 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -901,9 +901,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)
@@ -914,16 +916,14 @@ putfsent(struct statfs *ent)
opts = flags2opts(ent->f_flags);
opts = catopt(rw, opts);
- if (strncmp(ent->f_mntfromname, "<below>", 7) == 0 ||
- strncmp(ent->f_mntfromname, "<above>", 7) == 0) {
- strlcpy(ent->f_mntfromname,
- (strnstr(ent->f_mntfromname, ":", 8) +1),
- sizeof(ent->f_mntfromname));
+ if (strncmp(mntfromname, "<below>:", 8) == 0 ||
+ strncmp(mntfromname, "<above>:", 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" : " ");
@@ -939,7 +939,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)))