]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: make mnt_table_find_* more robust [coverity scan]
authorKarel Zak <kzak@redhat.com>
Wed, 27 Mar 2013 15:47:46 +0000 (16:47 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 27 Mar 2013 15:47:46 +0000 (16:47 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/tab.c

index f70ed7de08288a6e904f5297f78e046a03aa47da..9d524c1c178165a0ab7fe7b14f841313dbeca510 100644 (file)
@@ -444,6 +444,8 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
 
        if (!tb || !path)
                return NULL;
+       if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
+               return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup MOUNTPOINT: %s", path));
 
@@ -494,6 +496,8 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
 
        if (!tb || !path)
                return NULL;
+       if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
+               return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup TARGET: %s", path));
 
@@ -564,6 +568,8 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
        assert(tb);
        if (!tb || !path)
                return NULL;
+       if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
+               return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup srcpath: %s", path));
 
@@ -668,6 +674,8 @@ struct libmnt_fs *mnt_table_find_tag(struct libmnt_table *tb, const char *tag,
 
        if (!tb || !tag || !val)
                return NULL;
+       if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
+               return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup by TAG: %s %s", tag, val));
 
@@ -710,6 +718,8 @@ struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
 
        if (!tb)
                return NULL;
+       if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
+               return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup SOURCE: %s", source));
 
@@ -753,6 +763,8 @@ struct libmnt_fs *mnt_table_find_pair(struct libmnt_table *tb, const char *sourc
 
        if (!tb || !target)
                return NULL;
+       if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
+               return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup SOURCE: %s TARGET: %s", source, target));
 
@@ -788,6 +800,8 @@ struct libmnt_fs *mnt_table_find_devno(struct libmnt_table *tb,
 
        if (!tb)
                return NULL;
+       if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
+               return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup DEVNO: %d", (int) devno));