Skip to content

Commit

Permalink
findmnt: error on --target /non-exist
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
karelzak committed Dec 16, 2016
1 parent 0ed2a95 commit 80c31a0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libmount/src/tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 80c31a0

Please sign in to comment.