diff options
author | Karel Zak | 2014-02-20 16:59:11 +0100 |
---|---|---|
committer | Karel Zak | 2014-02-20 16:59:11 +0100 |
commit | 6c373810f5b1d32824371e9dff6ee5a006388f98 (patch) | |
tree | 287306034379ceea9232f217e99a506ffef72e9f /libmount/src/tab.c | |
parent | fallocate: fix missing sentinel for is_nul() (diff) | |
download | kernel-qcow2-util-linux-6c373810f5b1d32824371e9dff6ee5a006388f98.tar.gz kernel-qcow2-util-linux-6c373810f5b1d32824371e9dff6ee5a006388f98.tar.xz kernel-qcow2-util-linux-6c373810f5b1d32824371e9dff6ee5a006388f98.zip |
libmount: FS id and parent ID could be zero
It seems that linux 3.14 is able to produce things like:
19 0 8:3 / / rw,relatime - ext4 /dev/sda3 rw,data=ordered
^
Reported-by: Mantas Mikulėnas <grawity@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab.c')
-rw-r--r-- | libmount/src/tab.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/libmount/src/tab.c b/libmount/src/tab.c index 4c2f8a4ac..332312b68 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -505,7 +505,7 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root) assert(tb); assert(root); - if (!tb || !root) + if (!tb || !root || !is_mountinfo(tb)) return -EINVAL; DBG(TAB, mnt_debug_h(tb, "lookup root fs")); @@ -515,8 +515,6 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root) mnt_reset_iter(&itr, MNT_ITER_FORWARD); while(mnt_table_next_fs(tb, &itr, &fs) == 0) { int id = mnt_fs_get_parent_id(fs); - if (!id) - break; /* @tab is not a mountinfo file? */ if (!*root || id < root_id) { *root = fs; @@ -524,7 +522,7 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root) } } - return root_id ? 0 : -EINVAL; + return *root ? 0 : -EINVAL; } /** @@ -545,15 +543,13 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr, struct libmnt_fs *fs; int parent_id, lastchld_id = 0, chld_id = 0; - if (!tb || !itr || !parent) + if (!tb || !itr || !parent || !is_mountinfo(tb)) return -EINVAL; DBG(TAB, mnt_debug_h(tb, "lookup next child of '%s'", mnt_fs_get_target(parent))); parent_id = mnt_fs_get_id(parent); - if (!parent_id) - return -EINVAL; /* get ID of the previously returned child */ if (itr->head && itr->p != itr->head) { @@ -584,7 +580,7 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr, } } - if (!chld_id) + if (!*chld) return 1; /* end of iterator */ /* set the iterator to the @chld for the next call */ |