]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: be more restrictive about valid tag names
authorKarel Zak <kzak@redhat.com>
Tue, 2 Jul 2013 08:46:10 +0000 (10:46 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 2 Jul 2013 08:46:10 +0000 (10:46 +0200)
 # mount DUMMY=filename.img /mnt

The 'DUMMY=filename.img' is a filename and should not be
interpreted as tag name. The valid tag names are LABEL, UUID,
PARTLABEL and PARTUUID only.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/cache.c
libmount/src/fs.c
libmount/src/mountP.h
libmount/src/tab.c
libmount/src/utils.c

index 7b651228ab7f00bf52cc24f415fb5a4aa0b2ef5d..43a4daf4fe59a8270289bf5d1467192df5a1a320 100644 (file)
@@ -583,22 +583,18 @@ error:
 char *mnt_resolve_spec(const char *spec, struct libmnt_cache *cache)
 {
        char *cn = NULL;
+       char *t = NULL, *v = NULL;
 
        if (!spec)
                return NULL;
 
-       if (strchr(spec, '=')) {
-               char *tag, *val;
-
-               if (!blkid_parse_tag_string(spec, &tag, &val)) {
-                       cn = mnt_resolve_tag(tag, val, cache);
-
-                       free(tag);
-                       free(val);
-               }
-       } else
+       if (blkid_parse_tag_string(spec, &t, &v) == 0 && mnt_valid_tagname(t))
+               cn = mnt_resolve_tag(t, v, cache);
+       else
                cn = mnt_resolve_path(spec, cache);
 
+       free(t);
+       free(v);
        return cn;
 }
 
@@ -663,6 +659,7 @@ int test_read_tags(struct libmnt_test *ts, int argc, char *argv[])
 
        while(fgets(line, sizeof(line), stdin)) {
                size_t sz = strlen(line);
+               char *t = NULL, *v = NULL;
 
                if (sz > 0 && line[sz - 1] == '\n')
                        line[sz - 1] = '\0';
@@ -674,16 +671,14 @@ int test_read_tags(struct libmnt_test *ts, int argc, char *argv[])
                        if (mnt_cache_read_tags(cache, line) < 0)
                                fprintf(stderr, "%s: read tags failed\n", line);
 
-               } else if (strchr(line, '=')) {
-                       char *tag, *val;
+               } else if (blkid_parse_tag_string(line, &t, &v) == 0) {
                        const char *cn = NULL;
 
-                       if (!blkid_parse_tag_string(line, &tag, &val)) {
-                               cn = cache_find_tag(cache, tag, val);
+                       if (mnt_valid_tagname(t))
+                               cn = cache_find_tag(cache, t, v);
+                       free(t);
+                       free(v);
 
-                               free(tag);
-                               free(val);
-                       }
                        if (cn)
                                printf("%s: %s\n", line, cn);
                        else
index c95cdc7e759c6cff146b0e840b18ad59009ac6ad..75e3bbb26dc0a94cd32f5944cc30c6afaf3b18e4 100644 (file)
@@ -318,9 +318,12 @@ int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source)
 
        assert(fs);
 
-       if (source && *source != '/' && strchr(source, '=')) {
-               if (blkid_parse_tag_string(source, &t, &v) != 0)
-                       return -1;
+       if (source && blkid_parse_tag_string(source, &t, &v) == 0 &&
+           !mnt_valid_tagname(t)) {
+               /* parsable but unknown tag -- ignore */
+               free(t);
+               free(v);
+               t = v = NULL;
        }
 
        if (fs->source != source)
index e064a68495c7248281bdadc258859731f8a66aa6..7b0848f922040dbe594c597a607fb6ba19336c70 100644 (file)
@@ -136,6 +136,8 @@ extern int startswith(const char *s, const char *sx)
 
 extern char *stripoff_last_component(char *path);
 
+extern int mnt_valid_tagname(const char *tagname);
+
 extern int is_file_empty(const char *name);
 
 extern int mkdir_p(const char *path, mode_t mode);
index ef86627f8a11172fcea84ac77641c0b366de62b5..b3e47bd6e791005a3f511c980c6443cb2abea4e1 100644 (file)
@@ -716,7 +716,8 @@ struct libmnt_fs *mnt_table_find_tag(struct libmnt_table *tb, const char *tag,
 struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
                                        const char *source, int direction)
 {
-       struct libmnt_fs *fs = NULL;
+       struct libmnt_fs *fs;
+       char *t = NULL, *v = NULL;
 
        assert(tb);
 
@@ -727,18 +728,13 @@ struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
 
        DBG(TAB, mnt_debug_h(tb, "lookup SOURCE: '%s'", source));
 
-       if (source && *source && strchr(source, '=')) {
-               char *tag, *val;
-
-               if (blkid_parse_tag_string(source, &tag, &val) == 0) {
-
-                       fs = mnt_table_find_tag(tb, tag, val, direction);
-
-                       free(tag);
-                       free(val);
-               }
-       } else
+       if (blkid_parse_tag_string(source, &t, &v) || !mnt_valid_tagname(t))
                fs = mnt_table_find_srcpath(tb, source, direction);
+       else
+               fs = mnt_table_find_tag(tb, t, v, direction);
+
+       free(t);
+       free(v);
 
        return fs;
 }
index c328414f2213eddac3b144ea86f3b2204cd3f92c..6c5171eca13bfc10869f59503e184ecaffbed8c2 100644 (file)
@@ -65,6 +65,18 @@ int is_file_empty(const char *name)
        return (stat(name, &st) != 0 || st.st_size == 0);
 }
 
+int mnt_valid_tagname(const char *tagname)
+{
+       if (tagname && *tagname && (
+           strcmp("UUID", tagname) == 0 ||
+           strcmp("LABEL", tagname) == 0 ||
+           strcmp("PARTUUID", tagname) == 0 ||
+           strcmp("PARTLABEL", tagname) == 0))
+               return 1;
+
+       return 0;
+}
+
 int mnt_parse_offset(const char *str, size_t len, uintmax_t *res)
 {
        char *p;