|
|
05ad79 |
From f5ef29a5b5c51fe2039352dabcc4946fa2f55861 Mon Sep 17 00:00:00 2001
|
|
|
05ad79 |
From: Karel Zak <kzak@redhat.com>
|
|
|
05ad79 |
Date: Tue, 2 Jul 2013 10:46:10 +0200
|
|
|
05ad79 |
Subject: [PATCH 61/84] libmount: be more restrictive about valid tag names
|
|
|
05ad79 |
|
|
|
05ad79 |
# mount DUMMY=filename.img /mnt
|
|
|
05ad79 |
|
|
|
05ad79 |
The 'DUMMY=filename.img' is a filename and should not be
|
|
|
05ad79 |
interpreted as tag name. The valid tag names are LABEL, UUID,
|
|
|
05ad79 |
PARTLABEL and PARTUUID only.
|
|
|
05ad79 |
|
|
|
05ad79 |
Upstream: http://github.com/karelzak/util-linux/commit/2c6b25f01802808b142d450af3352605720899da
|
|
|
05ad79 |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1248003
|
|
|
05ad79 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
05ad79 |
---
|
|
|
05ad79 |
libmount/src/cache.c | 29 ++++++++++++-----------------
|
|
|
05ad79 |
libmount/src/fs.c | 9 ++++++---
|
|
|
05ad79 |
libmount/src/mountP.h | 2 ++
|
|
|
05ad79 |
libmount/src/tab.c | 20 ++++++++------------
|
|
|
05ad79 |
libmount/src/utils.c | 12 ++++++++++++
|
|
|
05ad79 |
5 files changed, 40 insertions(+), 32 deletions(-)
|
|
|
05ad79 |
|
|
|
05ad79 |
diff --git a/libmount/src/cache.c b/libmount/src/cache.c
|
|
|
05ad79 |
index 7b65122..43a4daf 100644
|
|
|
05ad79 |
--- a/libmount/src/cache.c
|
|
|
05ad79 |
+++ b/libmount/src/cache.c
|
|
|
05ad79 |
@@ -583,22 +583,18 @@ error:
|
|
|
05ad79 |
char *mnt_resolve_spec(const char *spec, struct libmnt_cache *cache)
|
|
|
05ad79 |
{
|
|
|
05ad79 |
char *cn = NULL;
|
|
|
05ad79 |
+ char *t = NULL, *v = NULL;
|
|
|
05ad79 |
|
|
|
05ad79 |
if (!spec)
|
|
|
05ad79 |
return NULL;
|
|
|
05ad79 |
|
|
|
05ad79 |
- if (strchr(spec, '=')) {
|
|
|
05ad79 |
- char *tag, *val;
|
|
|
05ad79 |
-
|
|
|
05ad79 |
- if (!blkid_parse_tag_string(spec, &tag, &val)) {
|
|
|
05ad79 |
- cn = mnt_resolve_tag(tag, val, cache);
|
|
|
05ad79 |
-
|
|
|
05ad79 |
- free(tag);
|
|
|
05ad79 |
- free(val);
|
|
|
05ad79 |
- }
|
|
|
05ad79 |
- } else
|
|
|
05ad79 |
+ if (blkid_parse_tag_string(spec, &t, &v) == 0 && mnt_valid_tagname(t))
|
|
|
05ad79 |
+ cn = mnt_resolve_tag(t, v, cache);
|
|
|
05ad79 |
+ else
|
|
|
05ad79 |
cn = mnt_resolve_path(spec, cache);
|
|
|
05ad79 |
|
|
|
05ad79 |
+ free(t);
|
|
|
05ad79 |
+ free(v);
|
|
|
05ad79 |
return cn;
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
@@ -663,6 +659,7 @@ int test_read_tags(struct libmnt_test *ts, int argc, char *argv[])
|
|
|
05ad79 |
|
|
|
05ad79 |
while(fgets(line, sizeof(line), stdin)) {
|
|
|
05ad79 |
size_t sz = strlen(line);
|
|
|
05ad79 |
+ char *t = NULL, *v = NULL;
|
|
|
05ad79 |
|
|
|
05ad79 |
if (sz > 0 && line[sz - 1] == '\n')
|
|
|
05ad79 |
line[sz - 1] = '\0';
|
|
|
05ad79 |
@@ -674,16 +671,14 @@ int test_read_tags(struct libmnt_test *ts, int argc, char *argv[])
|
|
|
05ad79 |
if (mnt_cache_read_tags(cache, line) < 0)
|
|
|
05ad79 |
fprintf(stderr, "%s: read tags failed\n", line);
|
|
|
05ad79 |
|
|
|
05ad79 |
- } else if (strchr(line, '=')) {
|
|
|
05ad79 |
- char *tag, *val;
|
|
|
05ad79 |
+ } else if (blkid_parse_tag_string(line, &t, &v) == 0) {
|
|
|
05ad79 |
const char *cn = NULL;
|
|
|
05ad79 |
|
|
|
05ad79 |
- if (!blkid_parse_tag_string(line, &tag, &val)) {
|
|
|
05ad79 |
- cn = cache_find_tag(cache, tag, val);
|
|
|
05ad79 |
+ if (mnt_valid_tagname(t))
|
|
|
05ad79 |
+ cn = cache_find_tag(cache, t, v);
|
|
|
05ad79 |
+ free(t);
|
|
|
05ad79 |
+ free(v);
|
|
|
05ad79 |
|
|
|
05ad79 |
- free(tag);
|
|
|
05ad79 |
- free(val);
|
|
|
05ad79 |
- }
|
|
|
05ad79 |
if (cn)
|
|
|
05ad79 |
printf("%s: %s\n", line, cn);
|
|
|
05ad79 |
else
|
|
|
05ad79 |
diff --git a/libmount/src/fs.c b/libmount/src/fs.c
|
|
|
05ad79 |
index c95cdc7..75e3bbb 100644
|
|
|
05ad79 |
--- a/libmount/src/fs.c
|
|
|
05ad79 |
+++ b/libmount/src/fs.c
|
|
|
05ad79 |
@@ -318,9 +318,12 @@ int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source)
|
|
|
05ad79 |
|
|
|
05ad79 |
assert(fs);
|
|
|
05ad79 |
|
|
|
05ad79 |
- if (source && *source != '/' && strchr(source, '=')) {
|
|
|
05ad79 |
- if (blkid_parse_tag_string(source, &t, &v) != 0)
|
|
|
05ad79 |
- return -1;
|
|
|
05ad79 |
+ if (source && blkid_parse_tag_string(source, &t, &v) == 0 &&
|
|
|
05ad79 |
+ !mnt_valid_tagname(t)) {
|
|
|
05ad79 |
+ /* parsable but unknown tag -- ignore */
|
|
|
05ad79 |
+ free(t);
|
|
|
05ad79 |
+ free(v);
|
|
|
05ad79 |
+ t = v = NULL;
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
if (fs->source != source)
|
|
|
05ad79 |
diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h
|
|
|
05ad79 |
index e064a68..7b0848f 100644
|
|
|
05ad79 |
--- a/libmount/src/mountP.h
|
|
|
05ad79 |
+++ b/libmount/src/mountP.h
|
|
|
05ad79 |
@@ -136,6 +136,8 @@ extern int startswith(const char *s, const char *sx)
|
|
|
05ad79 |
|
|
|
05ad79 |
extern char *stripoff_last_component(char *path);
|
|
|
05ad79 |
|
|
|
05ad79 |
+extern int mnt_valid_tagname(const char *tagname);
|
|
|
05ad79 |
+
|
|
|
05ad79 |
extern int is_file_empty(const char *name);
|
|
|
05ad79 |
|
|
|
05ad79 |
extern int mkdir_p(const char *path, mode_t mode);
|
|
|
05ad79 |
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
|
|
|
05ad79 |
index e3524a8..1ba1eec 100644
|
|
|
05ad79 |
--- a/libmount/src/tab.c
|
|
|
05ad79 |
+++ b/libmount/src/tab.c
|
|
|
05ad79 |
@@ -801,7 +801,8 @@ struct libmnt_fs *mnt_table_find_tag(struct libmnt_table *tb, const char *tag,
|
|
|
05ad79 |
struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
|
|
|
05ad79 |
const char *source, int direction)
|
|
|
05ad79 |
{
|
|
|
05ad79 |
- struct libmnt_fs *fs = NULL;
|
|
|
05ad79 |
+ struct libmnt_fs *fs;
|
|
|
05ad79 |
+ char *t = NULL, *v = NULL;
|
|
|
05ad79 |
|
|
|
05ad79 |
assert(tb);
|
|
|
05ad79 |
|
|
|
05ad79 |
@@ -812,18 +813,13 @@ struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
|
|
|
05ad79 |
|
|
|
05ad79 |
DBG(TAB, mnt_debug_h(tb, "lookup SOURCE: '%s'", source));
|
|
|
05ad79 |
|
|
|
05ad79 |
- if (source && *source && strchr(source, '=')) {
|
|
|
05ad79 |
- char *tag, *val;
|
|
|
05ad79 |
-
|
|
|
05ad79 |
- if (blkid_parse_tag_string(source, &tag, &val) == 0) {
|
|
|
05ad79 |
-
|
|
|
05ad79 |
- fs = mnt_table_find_tag(tb, tag, val, direction);
|
|
|
05ad79 |
-
|
|
|
05ad79 |
- free(tag);
|
|
|
05ad79 |
- free(val);
|
|
|
05ad79 |
- }
|
|
|
05ad79 |
- } else
|
|
|
05ad79 |
+ if (blkid_parse_tag_string(source, &t, &v) || !mnt_valid_tagname(t))
|
|
|
05ad79 |
fs = mnt_table_find_srcpath(tb, source, direction);
|
|
|
05ad79 |
+ else
|
|
|
05ad79 |
+ fs = mnt_table_find_tag(tb, t, v, direction);
|
|
|
05ad79 |
+
|
|
|
05ad79 |
+ free(t);
|
|
|
05ad79 |
+ free(v);
|
|
|
05ad79 |
|
|
|
05ad79 |
return fs;
|
|
|
05ad79 |
}
|
|
|
05ad79 |
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
|
|
|
05ad79 |
index 6a444ad..9305bb8 100644
|
|
|
05ad79 |
--- a/libmount/src/utils.c
|
|
|
05ad79 |
+++ b/libmount/src/utils.c
|
|
|
05ad79 |
@@ -65,6 +65,18 @@ int is_file_empty(const char *name)
|
|
|
05ad79 |
return (stat(name, &st) != 0 || st.st_size == 0);
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
+int mnt_valid_tagname(const char *tagname)
|
|
|
05ad79 |
+{
|
|
|
05ad79 |
+ if (tagname && *tagname && (
|
|
|
05ad79 |
+ strcmp("UUID", tagname) == 0 ||
|
|
|
05ad79 |
+ strcmp("LABEL", tagname) == 0 ||
|
|
|
05ad79 |
+ strcmp("PARTUUID", tagname) == 0 ||
|
|
|
05ad79 |
+ strcmp("PARTLABEL", tagname) == 0))
|
|
|
05ad79 |
+ return 1;
|
|
|
05ad79 |
+
|
|
|
05ad79 |
+ return 0;
|
|
|
05ad79 |
+}
|
|
|
05ad79 |
+
|
|
|
05ad79 |
int mnt_parse_offset(const char *str, size_t len, uintmax_t *res)
|
|
|
05ad79 |
{
|
|
|
05ad79 |
char *p;
|
|
|
05ad79 |
--
|
|
|
05ad79 |
2.7.4
|
|
|
05ad79 |
|