summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_update.c
diff options
context:
space:
mode:
authorKarel Zak2016-03-31 11:45:55 +0200
committerKarel Zak2016-03-31 11:45:55 +0200
commite9cd2e2bd9ec91a0b1050c4aa79555d142985924 (patch)
tree5da687b76440bcbf7ef925451dfb49379c21d6de /libmount/src/tab_update.c
parenttests: add DM error target for blkid (diff)
downloadkernel-qcow2-util-linux-e9cd2e2bd9ec91a0b1050c4aa79555d142985924.tar.gz
kernel-qcow2-util-linux-e9cd2e2bd9ec91a0b1050c4aa79555d142985924.tar.xz
kernel-qcow2-util-linux-e9cd2e2bd9ec91a0b1050c4aa79555d142985924.zip
libmount: Fix possible NULL dereference in get_btrfs_fs_root()
The function mnt_table_get_fs_root() should be robust enough to accept NULL as mountinfo -- the right behaviour is to default to '/'. The set_fs_root() (tab_update.c) has to understand when mountinfo is necessary (for bind mounts and btrfs). Reported-by: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab_update.c')
-rw-r--r--libmount/src/tab_update.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c
index 40adba98a..631e1cd9f 100644
--- a/libmount/src/tab_update.c
+++ b/libmount/src/tab_update.c
@@ -357,7 +357,7 @@ static int set_fs_root(struct libmnt_update *upd, struct libmnt_fs *fs,
{
struct libmnt_fs *src_fs;
char *fsroot = NULL;
- const char *src;
+ const char *src, *fstype;
int rc = 0;
DBG(UPDATE, ul_debug("setting FS root"));
@@ -366,16 +366,21 @@ static int set_fs_root(struct libmnt_update *upd, struct libmnt_fs *fs,
assert(upd->fs);
assert(fs);
+ fstype = mnt_fs_get_fstype(fs);
+
if (mountflags & MS_BIND) {
if (!upd->mountinfo)
upd->mountinfo = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);
-
src = mnt_fs_get_srcpath(fs);
if (src) {
rc = mnt_fs_set_bindsrc(upd->fs, src);
if (rc)
goto err;
}
+
+ } else if (fstype && (strcmp(fstype, "btrfs") == 0 || strcmp(fstype, "auto") == 0)) {
+ if (!upd->mountinfo)
+ upd->mountinfo = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);
}
src_fs = mnt_table_get_fs_root(upd->mountinfo, fs,