From: "Daniel P. Berrange" <berrange(a)redhat.com>
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 <berrange(a)redhat.com>
---
src/util/virfile.c | 4 +++-
tests/virfiledata/mounts2.txt | 33 +++++++++++++++++++++++++++++++++
tests/virfiletest.c | 4 ++++
3 files changed, 40 insertions(+), 1 deletion(-)
create mode 100644 tests/virfiledata/mounts2.txt
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 9e421eb..0155c20 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1619,7 +1619,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 9a64565..43e80b9 100644
--- a/tests/virfiletest.c
+++ b/tests/virfiletest.c
@@ -104,6 +104,9 @@ mymain(void)
static const char *wantmounts1rev[] = {
"/proc/sys/fs/binfmt_misc", "/proc/sys/fs/binfmt_misc",
"/proc"
};
+ static const char *wantmounts2[] = {
+ "/etc/aliases"
+ };
# define DO_TEST_MOUNT_SUBTREE(name, path, prefix, mounts, rev) \
do { \
@@ -116,6 +119,7 @@ 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",
wantmounts2, false);
#endif /* ! defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R */
return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
--
1.8.3.1