Blame SOURCES/0061-libmount-be-more-restrictive-about-valid-tag-names.patch

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