Blame SOURCES/0013-RH-warn-on-invalid-regex-instead-of-failing.patch

5c2e41
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5c2e41
From: Benjamin Marzinski <bmarzins@redhat.com>
5c2e41
Date: Mon, 6 Nov 2017 21:39:28 -0600
5c2e41
Subject: [PATCH] RH: warn on invalid regex instead of failing
5c2e41
5c2e41
multipath.conf used to allow "*" as a match everything regular expression,
5c2e41
instead of requiring ".*". Instead of erroring when the old style
5c2e41
regular expressions are used, it should print a warning and convert
5c2e41
them.
5c2e41
5c2e41
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
5c2e41
---
5c2e41
 libmultipath/dict.c   | 27 +++++++++++++++++++++------
5c2e41
 libmultipath/parser.c | 13 +++++++++++++
5c2e41
 libmultipath/parser.h |  1 +
5c2e41
 3 files changed, 35 insertions(+), 6 deletions(-)
5c2e41
5c2e41
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
5c2e41
index bf4701e..9d63d26 100644
5c2e41
--- a/libmultipath/dict.c
5c2e41
+++ b/libmultipath/dict.c
5c2e41
@@ -58,6 +58,21 @@ set_str(vector strvec, void *ptr)
5c2e41
 }
5c2e41
 
5c2e41
 static int
5c2e41
+set_regex(vector strvec, void *ptr)
5c2e41
+{
5c2e41
+	char **str_ptr = (char **)ptr;
5c2e41
+
5c2e41
+	if (*str_ptr)
5c2e41
+		FREE(*str_ptr);
5c2e41
+	*str_ptr = set_regex_value(strvec);
5c2e41
+
5c2e41
+	if (!*str_ptr)
5c2e41
+		return 1;
5c2e41
+
5c2e41
+	return 0;
5c2e41
+}
5c2e41
+
5c2e41
+static int
5c2e41
 set_yes_no(vector strvec, void *ptr)
5c2e41
 {
5c2e41
 	char * buff;
5c2e41
@@ -1336,7 +1351,7 @@ ble_ ## option ## _handler (struct config *conf, vector strvec)		\
5c2e41
 	if (!conf->option)						\
5c2e41
 		return 1;						\
5c2e41
 									\
5c2e41
-	buff = set_value(strvec);					\
5c2e41
+	buff = set_regex_value(strvec);					\
5c2e41
 	if (!buff)							\
5c2e41
 		return 1;						\
5c2e41
 									\
5c2e41
@@ -1352,7 +1367,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \
5c2e41
 	if (!conf->option)						\
5c2e41
 		return 1;						\
5c2e41
 									\
5c2e41
-	buff = set_value(strvec);					\
5c2e41
+	buff = set_regex_value(strvec);					\
5c2e41
 	if (!buff)							\
5c2e41
 		return 1;						\
5c2e41
 									\
5c2e41
@@ -1455,16 +1470,16 @@ device_handler(struct config *conf, vector strvec)
5c2e41
 	return 0;
5c2e41
 }
5c2e41
 
5c2e41
-declare_hw_handler(vendor, set_str)
5c2e41
+declare_hw_handler(vendor, set_regex)
5c2e41
 declare_hw_snprint(vendor, print_str)
5c2e41
 
5c2e41
-declare_hw_handler(product, set_str)
5c2e41
+declare_hw_handler(product, set_regex)
5c2e41
 declare_hw_snprint(product, print_str)
5c2e41
 
5c2e41
-declare_hw_handler(revision, set_str)
5c2e41
+declare_hw_handler(revision, set_regex)
5c2e41
 declare_hw_snprint(revision, print_str)
5c2e41
 
5c2e41
-declare_hw_handler(bl_product, set_str)
5c2e41
+declare_hw_handler(bl_product, set_regex)
5c2e41
 declare_hw_snprint(bl_product, print_str)
5c2e41
 
5c2e41
 declare_hw_handler(hwhandler, set_str)
5c2e41
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
5c2e41
index 92ef7cf..4289336 100644
5c2e41
--- a/libmultipath/parser.c
5c2e41
+++ b/libmultipath/parser.c
5c2e41
@@ -384,6 +384,19 @@ set_value(vector strvec)
5c2e41
 	return alloc;
5c2e41
 }
5c2e41
 
5c2e41
+void *
5c2e41
+set_regex_value(vector strvec)
5c2e41
+{
5c2e41
+	char *buff = set_value(strvec);
5c2e41
+
5c2e41
+	if (buff && strcmp("*", buff) == 0) {
5c2e41
+		condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\"");
5c2e41
+		FREE(buff);
5c2e41
+		return strdup(".*");
5c2e41
+	}
5c2e41
+	return buff;
5c2e41
+}
5c2e41
+
5c2e41
 /* non-recursive configuration stream handler */
5c2e41
 static int kw_level = 0;
5c2e41
 
5c2e41
diff --git a/libmultipath/parser.h b/libmultipath/parser.h
5c2e41
index 62906e9..b791705 100644
5c2e41
--- a/libmultipath/parser.h
5c2e41
+++ b/libmultipath/parser.h
5c2e41
@@ -77,6 +77,7 @@ extern void dump_keywords(vector keydump, int level);
5c2e41
 extern void free_keywords(vector keywords);
5c2e41
 extern vector alloc_strvec(char *string);
5c2e41
 extern void *set_value(vector strvec);
5c2e41
+extern void *set_regex_value(vector strvec);
5c2e41
 extern int process_file(struct config *conf, char *conf_file);
5c2e41
 extern struct keyword * find_keyword(vector keywords, vector v, char * name);
5c2e41
 int snprint_keyword(char *buff, int len, char *fmt, struct keyword *kw,
5c2e41
-- 
5c2e41
2.7.4
5c2e41