summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2013-06-17 13:02:15 +0200
committerKarel Zak2013-06-17 13:02:15 +0200
commit7ba207e781c7af3945d3a718651b87425685131e (patch)
treed8edf4afc0d81a68f94a68c5421b4446677e70c2
parentlibblkid: support pseudo PARTUUID= for MBR (diff)
downloadkernel-qcow2-util-linux-7ba207e781c7af3945d3a718651b87425685131e.tar.gz
kernel-qcow2-util-linux-7ba207e781c7af3945d3a718651b87425685131e.tar.xz
kernel-qcow2-util-linux-7ba207e781c7af3945d3a718651b87425685131e.zip
libmount: be robust for empty target/source strings
* lib/canonicalize.c: don't interpret empty strings as relative paths * libmount: more robust libmnt_table find function and debug messages References: https://bugzilla.novell.com/show_bug.cgi?id=825150 Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--lib/canonicalize.c7
-rw-r--r--libmount/src/context_umount.c13
-rw-r--r--libmount/src/tab.c28
-rw-r--r--sys-utils/umount.c5
4 files changed, 36 insertions, 17 deletions
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index 727806e1e..548e29b75 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -151,6 +151,9 @@ canonicalize_dm_name(const char *ptname)
size_t sz;
char path[256], name[256], *res = NULL;
+ if (!ptname || !*ptname)
+ return NULL;
+
snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptname);
if (!(f = fopen(path, "r" UL_CLOEXECSTR)))
return NULL;
@@ -173,7 +176,7 @@ canonicalize_path(const char *path)
char canonical[PATH_MAX+2];
char *p;
- if (path == NULL)
+ if (!path || !*path)
return NULL;
if (!myrealpath(path, canonical, PATH_MAX+1))
@@ -199,7 +202,7 @@ canonicalize_path_restricted(const char *path)
uid_t euid;
gid_t egid;
- if (path == NULL)
+ if (!path || !*path)
return NULL;
euid = geteuid();
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index 4a8659c9c..7707991eb 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -71,11 +71,17 @@ int mnt_context_find_umount_fs(struct libmnt_context *cxt,
struct libmnt_cache *cache = NULL;
char *cn_tgt = NULL, *loopdev = NULL;
+ if (pfs)
+ *pfs = NULL;
+
if (!cxt || !tgt || !pfs)
return -EINVAL;
DBG(CXT, mnt_debug_h(cxt, "umount: lookup FS for '%s'", tgt));
+ if (!*tgt)
+ return 1; /* empty string is not error */
+
/*
* The mtab file maybe huge and on systems with utab we have to merge
* userspace mount options into /proc/self/mountinfo. This all is
@@ -169,9 +175,12 @@ try_loopdev:
}
}
- *pfs = fs;
+ if (pfs)
+ *pfs = fs;
free(loopdev);
+ DBG(CXT, mnt_debug_h(cxt, "umount fs: %s", fs ? mnt_fs_get_target(fs) :
+ "<not found>"));
return fs ? 0 : 1;
err:
free(loopdev);
@@ -197,7 +206,7 @@ static int lookup_umount_fs(struct libmnt_context *cxt)
if (rc < 0)
return rc;
if (rc == 1 || !fs) {
- DBG(CXT, mnt_debug_h(cxt, "umount: cannot find %s in mtab", tgt));
+ DBG(CXT, mnt_debug_h(cxt, "umount: cannot find '%s' in mtab", tgt));
return 0;
}
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 11a297814..ef86627f8 100644
--- a/libmount/src/tab.c
+++ b/libmount/src/tab.c
@@ -274,7 +274,7 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
if (!tb || !itr || !parent)
return -EINVAL;
- DBG(TAB, mnt_debug_h(tb, "lookup next child of %s",
+ DBG(TAB, mnt_debug_h(tb, "lookup next child of '%s'",
mnt_fs_get_target(parent)));
parent_id = mnt_fs_get_id(parent);
@@ -442,12 +442,12 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
{
char *mnt;
- if (!tb || !path)
+ if (!tb || !path || !*path)
return NULL;
if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
return NULL;
- DBG(TAB, mnt_debug_h(tb, "lookup MOUNTPOINT: %s", path));
+ DBG(TAB, mnt_debug_h(tb, "lookup MOUNTPOINT: '%s'", path));
mnt = strdup(path);
if (!mnt)
@@ -494,12 +494,12 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
assert(tb);
assert(path);
- if (!tb || !path)
+ if (!tb || !path || !*path)
return NULL;
if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
return NULL;
- DBG(TAB, mnt_debug_h(tb, "lookup TARGET: %s", path));
+ DBG(TAB, mnt_debug_h(tb, "lookup TARGET: '%s'", path));
/* native @target */
mnt_reset_iter(&itr, direction);
@@ -510,6 +510,8 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
if (!tb->cache || !(cn = mnt_resolve_path(path, tb->cache)))
return NULL;
+ DBG(TAB, mnt_debug_h(tb, "lookup canonical TARGET: '%s'", cn));
+
/* canonicalized paths in struct libmnt_table */
mnt_reset_iter(&itr, direction);
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
@@ -566,12 +568,12 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
const char *p;
assert(tb);
- if (!tb || !path)
+ if (!tb || !path || !*path)
return NULL;
if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
return NULL;
- DBG(TAB, mnt_debug_h(tb, "lookup srcpath: %s", path));
+ DBG(TAB, mnt_debug_h(tb, "lookup SRCPATH: '%s'", path));
/* native paths */
mnt_reset_iter(&itr, direction);
@@ -585,6 +587,8 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
if (!path || !tb->cache || !(cn = mnt_resolve_path(path, tb->cache)))
return NULL;
+ DBG(TAB, mnt_debug_h(tb, "lookup canonical SRCPATH: '%s'", cn));
+
/* canonicalized paths in struct libmnt_table */
if (ntags < mnt_table_get_nents(tb)) {
mnt_reset_iter(&itr, direction);
@@ -672,7 +676,7 @@ struct libmnt_fs *mnt_table_find_tag(struct libmnt_table *tb, const char *tag,
assert(tag);
assert(val);
- if (!tb || !tag || !val)
+ if (!tb || !tag || !*tag || !val)
return NULL;
if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
return NULL;
@@ -721,9 +725,9 @@ struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
return NULL;
- DBG(TAB, mnt_debug_h(tb, "lookup SOURCE: %s", source));
+ DBG(TAB, mnt_debug_h(tb, "lookup SOURCE: '%s'", source));
- if (source && strchr(source, '=')) {
+ if (source && *source && strchr(source, '=')) {
char *tag, *val;
if (blkid_parse_tag_string(source, &tag, &val) == 0) {
@@ -761,7 +765,7 @@ struct libmnt_fs *mnt_table_find_pair(struct libmnt_table *tb, const char *sourc
assert(tb);
assert(target);
- if (!tb || !target)
+ if (!tb || !target || !*target || !source || !*source)
return NULL;
if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)
return NULL;
@@ -841,7 +845,7 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
assert(fs);
assert(fsroot);
- DBG(TAB, mnt_debug("lookup fs-root for %s", mnt_fs_get_source(fs)));
+ DBG(TAB, mnt_debug("lookup fs-root for '%s'", mnt_fs_get_source(fs)));
fstype = mnt_fs_get_fstype(fs);
diff --git a/sys-utils/umount.c b/sys-utils/umount.c
index e3f0e2dd0..c3b8187ce 100644
--- a/sys-utils/umount.c
+++ b/sys-utils/umount.c
@@ -236,7 +236,10 @@ static int mk_exit_code(struct libmnt_context *cxt, int rc)
tgt);
break;
case ENOENT:
- warnx(_("%s: not found"), tgt);
+ if (tgt && *tgt)
+ warnx(_("%s: mountpoint not found"), tgt);
+ else
+ warnx(_("undefined mountpoint"));
break;
case EPERM:
warnx(_("%s: must be superuser to unmount"), tgt);