From c047ae52f61a3dee588968a11141c2200f1f2e44 Mon Sep 17 00:00:00 2001 Message-Id: From: "Daniel P. Berrange" Date: Mon, 2 Dec 2013 13:39:12 +0000 Subject: [PATCH] Fix bug in identifying sub-mounts For https://bugzilla.redhat.com/show_bug.cgi?id=1035403 The code for extracting sub-mounts would just do a STRPREFIX check on the mount. This was flawed because if there were the following mounts /etc/aliases /etc/aliases.db and '/etc/aliases' was asked for, it would return both even though the latter isn't a sub-mount. Signed-off-by: Daniel P. Berrange (cherry picked from commit 84fd470d3d8c8e27abca8b2f3fc601c7cd58eadb) Signed-off-by: Jiri Denemark --- src/util/virfile.c | 4 +++- tests/virfiledata/mounts2.txt | 33 +++++++++++++++++++++++++++++++++ tests/virfiletest.c | 8 ++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/virfiledata/mounts2.txt diff --git a/src/util/virfile.c b/src/util/virfile.c index e2a5f7a..9b3a4ad 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1520,7 +1520,9 @@ virFileGetMountSubtreeImpl(const char *mtabpath, } while (getmntent_r(procmnt, &mntent, mntbuf, sizeof(mntbuf)) != NULL) { - if (!STRPREFIX(mntent.mnt_dir, prefix)) + if (!(STREQ(mntent.mnt_dir, prefix) || + (STRPREFIX(mntent.mnt_dir, prefix) && + mntent.mnt_dir[strlen(prefix)] == '/'))) continue; if (VIR_EXPAND_N(mounts, nmounts, nmounts ? 1 : 2) < 0) diff --git a/tests/virfiledata/mounts2.txt b/tests/virfiledata/mounts2.txt new file mode 100644 index 0000000..8b47dde --- /dev/null +++ b/tests/virfiledata/mounts2.txt @@ -0,0 +1,33 @@ +rootfs / rootfs rw 0 0 +proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 +sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0 +devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=8057768k,nr_inodes=2014442,mode=755 0 0 +securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0 +selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0 +tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0 +devpts /dev/pts devpts rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 +tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=755 0 0 +tmpfs /sys/fs/cgroup tmpfs rw,seclabel,nosuid,nodev,noexec,mode=755 0 0 +cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0 +pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0 +cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0 +cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0 +cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 +cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0 +cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0 +cgroup /sys/fs/cgroup/net_cls cgroup rw,nosuid,nodev,noexec,relatime,net_cls 0 0 +cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0 +cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0 +/dev/mapper/fedora-root / ext4 rw,seclabel,relatime,data=ordered 0 0 +systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=33,pgrp=1,timeout=300,minproto=5,maxproto=5,direct 0 0 +configfs /sys/kernel/config configfs rw,relatime 0 0 +debugfs /sys/kernel/debug debugfs rw,relatime 0 0 +mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0 +tmpfs /tmp tmpfs rw,seclabel 0 0 +hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime 0 0 +binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0 +/dev/sda1 /boot ext4 rw,seclabel,relatime,stripe=4,data=ordered 0 0 +fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0 +gvfsd-fuse /run/user/501/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=501,group_id=501 0 0 +/dev/mapper/fedora-root /etc/aliases.db ext4 rw,seclabel,relatime,data=ordered 0 0 +/dev/mapper/fedora-root /etc/aliases ext4 rw,seclabel,relatime,data=ordered 0 0 diff --git a/tests/virfiletest.c b/tests/virfiletest.c index fd6761d..273147e 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -104,6 +104,12 @@ mymain(void) static const char *wantmounts1rev[] = { "/proc/sys/fs/binfmt_misc", "/proc/sys/fs/binfmt_misc", "/proc" }; + static const char *wantmounts2a[] = { + "/etc/aliases" + }; + static const char *wantmounts2b[] = { + "/etc/aliases.db" + }; # define DO_TEST_MOUNT_SUBTREE(name, path, prefix, mounts, rev) \ do { \ @@ -116,6 +122,8 @@ mymain(void) DO_TEST_MOUNT_SUBTREE("/proc normal", MTAB_PATH1, "/proc", wantmounts1, false); DO_TEST_MOUNT_SUBTREE("/proc reverse", MTAB_PATH1, "/proc", wantmounts1rev, true); + DO_TEST_MOUNT_SUBTREE("/etc/aliases", MTAB_PATH2, "/etc/aliases", wantmounts2a, false); + DO_TEST_MOUNT_SUBTREE("/etc/aliases.db", MTAB_PATH2, "/etc/aliases.db", wantmounts2b, false); #endif /* ! defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R */ return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS; -- 1.8.4.5