mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
Fix bug in identifying sub-mounts
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@redhat.com>
This commit is contained in:
parent
d45b833d14
commit
84fd470d3d
@ -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)
|
||||
|
33
tests/virfiledata/mounts2.txt
Normal file
33
tests/virfiledata/mounts2.txt
Normal file
@ -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
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user