1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
From 0000000000000000000000000000000000000000 Mon Sep 17
00:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Mon, 6 Nov
2017 21:39:28 -0600 Subject: [PATCH] RH: warn on invalid regex instead of
failing
multipath.conf used to allow "*" as a match everything regular expression,
instead of requiring ".*". Instead of erroring when the old style
regular expressions are used, it should print a warning and convert
them.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Upstream-Status: Pending
update this patch to 0.8.2
Signed-off-by: Changqing Li <changqing.li@windriver.com>
[OP: Rebase to 0.9.3]
[OP: adjusted FREE() -> free(), made set_regex_value() static]
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
---
libmultipath/dict.c | 42 +++++++++++++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 7 deletions(-)
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index aa93fe43..55a22d32 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -155,6 +155,34 @@ set_str_noslash(vector strvec, void *ptr, const char *file, int line_nr)
return 0;
}
+static void *
+set_regex_value(vector strvec)
+{
+ char *buff = set_value(strvec);
+
+ if (buff && strcmp("*", buff) == 0) {
+ condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\"");
+ free(buff);
+ return strdup(".*");
+ }
+ return buff;
+}
+
+static int
+set_regex(vector strvec, void *ptr, const char *file, int line_nr)
+{
+ char **str_ptr = (char **)ptr;
+
+ if (*str_ptr)
+ free(*str_ptr);
+ *str_ptr = set_regex_value(strvec);
+
+ if (!*str_ptr)
+ return 1;
+
+ return 0;
+}
+
static int
set_yes_no(vector strvec, void *ptr, const char *file, int line_nr)
{
@@ -1679,8 +1707,8 @@ ble_ ## option ## _handler (struct config *conf, vector strvec, \
\
if (!conf->option) \
return 1; \
- \
- buff = set_value(strvec); \
+ \
+ buff = set_regex_value(strvec); \
if (!buff) \
return 1; \
\
@@ -1700,7 +1728,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec, \
if (!conf->option) \
return 1; \
\
- buff = set_value(strvec); \
+ buff = set_regex_value(strvec); \
if (!buff) \
return 1; \
\
@@ -1806,16 +1834,16 @@ device_handler(struct config *conf, vector strvec, const char *file,
return 0;
}
-declare_hw_handler(vendor, set_str)
+declare_hw_handler(vendor, set_regex)
declare_hw_snprint(vendor, print_str)
-declare_hw_handler(product, set_str)
+declare_hw_handler(product, set_regex)
declare_hw_snprint(product, print_str)
-declare_hw_handler(revision, set_str)
+declare_hw_handler(revision, set_regex)
declare_hw_snprint(revision, print_str)
-declare_hw_handler(bl_product, set_str)
+declare_hw_handler(bl_product, set_regex)
declare_hw_snprint(bl_product, print_str)
declare_hw_handler(hwhandler, set_str)
--
2.38.1
|