1From 9f1075f82ecd39a9960f868eef890baf2ba36d4e Mon Sep 17 00:00:00 2001
2From: Changqing Li <changqing.li@windriver.com>
3Date: Fri, 1 Mar 2024 11:45:10 +0800
4Subject: [PATCH] RH: warn on invalid regex instead of failing
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
15[OP: Rebase to 0.9.3]
16[OP: adjusted FREE() -> free(), made set_regex_value() static]
17Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
18
19Rebase to 0.9.8
20Signed-off-by: Changqing Li <changqing.li@windriver.com>
21---
22 libmultipath/dict.c | 40 ++++++++++++++++++++++++++++++++++------
23 1 file changed, 34 insertions(+), 6 deletions(-)
24
25diff --git a/libmultipath/dict.c b/libmultipath/dict.c
26index a06a6138..a734ba9b 100644
27--- a/libmultipath/dict.c
28+++ b/libmultipath/dict.c
29@@ -189,6 +189,34 @@ set_str_noslash(vector strvec, void *ptr, const char *file, int line_nr)
30 	return 0;
31 }
32
33+static void *
34+set_regex_value(vector strvec)
35+{
36+       char *buff = set_value(strvec);
37+
38+       if (buff && strcmp("*", buff) == 0) {
39+               condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\"");
40+               free(buff);
41+               return strdup(".*");
42+       }
43+       return buff;
44+}
45+
46+static int
47+set_regex(vector strvec, void *ptr, const char *file, int line_nr)
48+{
49+       char **str_ptr = (char **)ptr;
50+
51+       if (*str_ptr)
52+               free(*str_ptr);
53+       *str_ptr = set_regex_value(strvec);
54+
55+       if (!*str_ptr)
56+               return 1;
57+
58+       return 0;
59+}
60+
61 static int
62 set_yes_no(vector strvec, void *ptr, const char *file, int line_nr)
63 {
64@@ -1854,7 +1882,7 @@ ble_ ## option ## _handler (struct config *conf, vector strvec,		\
65 	if (!conf->option)						\
66 		return 1;						\
67 									\
68-	buff = set_value(strvec);					\
69+	buff = set_regex_value(strvec);					\
70 	if (!buff)							\
71 		return 1;						\
72 									\
73@@ -1874,7 +1902,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec, \
74 	if (!conf->option)						\
75 		return 1;						\
76 									\
77-	buff = set_value(strvec);					\
78+	buff = set_regex_value(strvec);					\
79 	if (!buff)							\
80 		return 1;						\
81 									\
82@@ -1980,16 +2008,16 @@ device_handler(struct config *conf, vector strvec, const char *file,
83 	return 0;
84 }
85
86-declare_hw_handler(vendor, set_str)
87+declare_hw_handler(vendor, set_regex)
88 declare_hw_snprint(vendor, print_str)
89
90-declare_hw_handler(product, set_str)
91+declare_hw_handler(product, set_regex)
92 declare_hw_snprint(product, print_str)
93
94-declare_hw_handler(revision, set_str)
95+declare_hw_handler(revision, set_regex)
96 declare_hw_snprint(revision, print_str)
97
98-declare_hw_handler(bl_product, set_str)
99+declare_hw_handler(bl_product, set_regex)
100 declare_hw_snprint(bl_product, print_str)
101
102 declare_hw_arg_str_handler(hwhandler, 0)
103--
1042.25.1
105
106