aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/multipath-tools/files/0007-RH-warn-on-invalid-regex-instead-of-failing.patch
blob: c64b8aeabc7c5d33b86a5b4e5fc6c8f036fa1aa8 (plain)
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
From 49d0b0279f54ceb96878e8e72e828efbb84a534c Mon Sep 17 00:00:00 2001
From: Changqing Li <changqing.li@windriver.com>
Date: Fri, 1 Mar 2024 11:45:10 +0800
Subject: [PATCH 07/12] 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

[OP: Rebase to 0.9.3]
[OP: adjusted FREE() -> free(), made set_regex_value() static]
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>

Rebase to 0.9.8
Signed-off-by: Changqing Li <changqing.li@windriver.com>
---
 libmultipath/dict.c | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/libmultipath/dict.c b/libmultipath/dict.c
index 5af036b7..e494419d 100644
--- a/libmultipath/dict.c
+++ b/libmultipath/dict.c
@@ -189,6 +189,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)
 {
@@ -1798,7 +1826,7 @@ 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;						\
 									\
@@ -1818,7 +1846,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;						\
 									\
@@ -1924,16 +1952,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_arg_str_handler(hwhandler, 0)
-- 
2.25.1