Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 |
| 2 | 00:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Mon, 6 Nov |
| 3 | 2017 21:39:28 -0600 Subject: [PATCH] RH: warn on invalid regex instead of |
| 4 | failing |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 5 | |
| 6 | multipath.conf used to allow "*" as a match everything regular expression, |
| 7 | instead of requiring ".*". Instead of erroring when the old style |
| 8 | regular expressions are used, it should print a warning and convert |
| 9 | them. |
| 10 | |
| 11 | Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 12 | |
| 13 | Upstream-Status: Pending |
| 14 | |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 15 | update this patch to 0.8.2 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 16 | |
| 17 | Signed-off-by: Changqing Li <changqing.li@windriver.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | --- |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 19 | libmultipath/dict.c | 29 ++++++++++++++++++++++------- |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 20 | libmultipath/parser.c | 13 +++++++++++++ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 21 | libmultipath/parser.h | 1 + |
| 22 | 3 files changed, 36 insertions(+), 7 deletions(-) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 23 | |
| 24 | diff --git a/libmultipath/dict.c b/libmultipath/dict.c |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 25 | index c6eba0f..05ed3d8 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 26 | --- a/libmultipath/dict.c |
| 27 | +++ b/libmultipath/dict.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 28 | @@ -59,6 +59,21 @@ set_str(vector strvec, void *ptr) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static int |
| 32 | +set_regex(vector strvec, void *ptr) |
| 33 | +{ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 34 | + char **str_ptr = (char **)ptr; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 35 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 | + if (*str_ptr) |
| 37 | + FREE(*str_ptr); |
| 38 | + *str_ptr = set_regex_value(strvec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 39 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 40 | + if (!*str_ptr) |
| 41 | + return 1; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 42 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 43 | + return 0; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 44 | +} |
| 45 | + |
| 46 | +static int |
| 47 | set_yes_no(vector strvec, void *ptr) |
| 48 | { |
| 49 | char * buff; |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 50 | @@ -1415,8 +1430,8 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 | \ |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 61 | @@ -1432,7 +1447,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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 | \ |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 70 | @@ -1535,16 +1550,16 @@ device_handler(struct config *conf, vector strvec) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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) |
| 91 | diff --git a/libmultipath/parser.c b/libmultipath/parser.c |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 92 | index e00c5ff..6ca5842 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 93 | --- a/libmultipath/parser.c |
| 94 | +++ b/libmultipath/parser.c |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 95 | @@ -382,6 +382,19 @@ oom: |
| 96 | return NULL; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | +void * |
| 100 | +set_regex_value(vector strvec) |
| 101 | +{ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 102 | + char *buff = set_value(strvec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 103 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 110 | +} |
| 111 | + |
| 112 | /* non-recursive configuration stream handler */ |
| 113 | static int kw_level = 0; |
| 114 | |
| 115 | diff --git a/libmultipath/parser.h b/libmultipath/parser.h |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 116 | index 62906e9..b791705 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 117 | --- a/libmultipath/parser.h |
| 118 | +++ b/libmultipath/parser.h |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 119 | @@ -77,6 +77,7 @@ extern void dump_keywords(vector keydump, int level); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 120 | extern void free_keywords(vector keywords); |
| 121 | extern vector alloc_strvec(char *string); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 122 | extern void *set_value(vector strvec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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, |
Brad Bishop | 00ab237 | 2019-10-14 11:06:18 -0400 | [diff] [blame] | 127 | -- |
| 128 | 2.7.4 |
| 129 | |