Blame SOURCES/0016-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
8444ee
index d6d8b79b..07d2ba8f 100644
5c2e41
--- a/libmultipath/dict.c
5c2e41
+++ b/libmultipath/dict.c
5c2e41
@@ -58,6 +58,21 @@ set_str(vector strvec, void *ptr)
a1c519
 	return 0;
5c2e41
 }
5c2e41
 
a1c519
+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
+
a1c519
 static int
5c2e41
 set_yes_no(vector strvec, void *ptr)
5c2e41
 {
8444ee
@@ -1455,7 +1470,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
 									\
8444ee
@@ -1471,7 +1486,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
 									\
8444ee
@@ -1574,16 +1589,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
8444ee
index e00c5fff..15495d26 100644
5c2e41
--- a/libmultipath/parser.c
5c2e41
+++ b/libmultipath/parser.c
8444ee
@@ -382,6 +382,19 @@ oom:
8444ee
 	return NULL;
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
8444ee
index 62906e98..b7917052 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
-- 
a1c519
2.17.2
5c2e41