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

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