1From 0000000000000000000000000000000000000000 Mon Sep 17 200:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Mon, 6 Nov 32017 21:39:28 -0600 Subject: [PATCH] RH: warn on invalid regex instead of 4failing 5 6multipath.conf used to allow "*" as a match everything regular expression, 7instead of requiring ".*". Instead of erroring when the old style 8regular expressions are used, it should print a warning and convert 9them. 10 11Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> 12 13Upstream-Status: Pending 14 15update this patch to 0.8.2 16 17Signed-off-by: Changqing Li <changqing.li@windriver.com> 18--- 19 libmultipath/dict.c | 29 ++++++++++++++++++++++------- 20 libmultipath/parser.c | 13 +++++++++++++ 21 libmultipath/parser.h | 1 + 22 3 files changed, 36 insertions(+), 7 deletions(-) 23 24diff --git a/libmultipath/dict.c b/libmultipath/dict.c 25index c6eba0f..05ed3d8 100644 26--- a/libmultipath/dict.c 27+++ b/libmultipath/dict.c 28@@ -59,6 +59,21 @@ set_str(vector strvec, void *ptr) 29 } 30 31 static int 32+set_regex(vector strvec, void *ptr) 33+{ 34+ char **str_ptr = (char **)ptr; 35+ 36+ if (*str_ptr) 37+ FREE(*str_ptr); 38+ *str_ptr = set_regex_value(strvec); 39+ 40+ if (!*str_ptr) 41+ return 1; 42+ 43+ return 0; 44+} 45+ 46+static int 47 set_yes_no(vector strvec, void *ptr) 48 { 49 char * buff; 50@@ -1415,8 +1430,8 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \ 51 \ 52 if (!conf->option) \ 53 return 1; \ 54- \ 55- buff = set_value(strvec); \ 56+ \ 57+ buff = set_regex_value(strvec); \ 58 if (!buff) \ 59 return 1; \ 60 \ 61@@ -1432,7 +1447,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \ 62 if (!conf->option) \ 63 return 1; \ 64 \ 65- buff = set_value(strvec); \ 66+ buff = set_regex_value(strvec); \ 67 if (!buff) \ 68 return 1; \ 69 \ 70@@ -1535,16 +1550,16 @@ device_handler(struct config *conf, vector strvec) 71 return 0; 72 } 73 74-declare_hw_handler(vendor, set_str) 75+declare_hw_handler(vendor, set_regex) 76 declare_hw_snprint(vendor, print_str) 77 78-declare_hw_handler(product, set_str) 79+declare_hw_handler(product, set_regex) 80 declare_hw_snprint(product, print_str) 81 82-declare_hw_handler(revision, set_str) 83+declare_hw_handler(revision, set_regex) 84 declare_hw_snprint(revision, print_str) 85 86-declare_hw_handler(bl_product, set_str) 87+declare_hw_handler(bl_product, set_regex) 88 declare_hw_snprint(bl_product, print_str) 89 90 declare_hw_handler(hwhandler, set_str) 91diff --git a/libmultipath/parser.c b/libmultipath/parser.c 92index e00c5ff..6ca5842 100644 93--- a/libmultipath/parser.c 94+++ b/libmultipath/parser.c 95@@ -382,6 +382,19 @@ oom: 96 return NULL; 97 } 98 99+void * 100+set_regex_value(vector strvec) 101+{ 102+ char *buff = set_value(strvec); 103+ 104+ if (buff && strcmp("*", buff) == 0) { 105+ condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\""); 106+ FREE(buff); 107+ return strdup(".*"); 108+ } 109+ return buff; 110+} 111+ 112 /* non-recursive configuration stream handler */ 113 static int kw_level = 0; 114 115diff --git a/libmultipath/parser.h b/libmultipath/parser.h 116index 62906e9..b791705 100644 117--- a/libmultipath/parser.h 118+++ b/libmultipath/parser.h 119@@ -77,6 +77,7 @@ extern void dump_keywords(vector keydump, int level); 120 extern void free_keywords(vector keywords); 121 extern vector alloc_strvec(char *string); 122 extern void *set_value(vector strvec); 123+extern void *set_regex_value(vector strvec); 124 extern int process_file(struct config *conf, char *conf_file); 125 extern struct keyword * find_keyword(vector keywords, vector v, char * name); 126 int snprint_keyword(char *buff, int len, char *fmt, struct keyword *kw, 127-- 1282.7.4 129 130