]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findmnt: error on --target /non-exist
authorKarel Zak <kzak@redhat.com>
Fri, 16 Dec 2016 11:46:45 +0000 (12:46 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 16 Dec 2016 12:00:45 +0000 (13:00 +0100)
The original --target implementation (< v2.27) has been based on
stat(), so it was usable for valid paths only.

The new implementation is based on search in the mountinfo file, so it
works for arbitrary crazy path. This is not backwardly compatible and
if the path does not exist then it still returns at least root
directory mount entry.

This patch forces mnt_table_find_mountpoint() to check if the path is
valid before we search in the mountinfo file.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/tab.c

index f72dcf1c2ea169cc411f802f9f3435e7566e915e..85fd427b54d85daba075105c86de60b1e911d571 100644 (file)
@@ -780,6 +780,7 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
                                            int direction)
 {
        char *mnt;
+       struct stat st;
 
        if (!tb || !path || !*path)
                return NULL;
@@ -788,6 +789,9 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
 
        DBG(TAB, ul_debugobj(tb, "lookup MOUNTPOINT: '%s'", path));
 
+       if (mnt_stat_mountpoint(path, &st))
+               return NULL;
+
        mnt = strdup(path);
        if (!mnt)
                return NULL;