Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Benjamin Marzinski <bmarzins@redhat.com> |
| 3 | Date: Mon, 6 Nov 2017 21:39:28 -0600 |
| 4 | Subject: [PATCH] RH: warn on invalid regex instead of failing |
| 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> |
| 12 | --- |
| 13 | libmultipath/dict.c | 27 +++++++++++++++++++++------ |
| 14 | libmultipath/parser.c | 13 +++++++++++++ |
| 15 | libmultipath/parser.h | 1 + |
| 16 | 3 files changed, 35 insertions(+), 6 deletions(-) |
| 17 | |
| 18 | diff --git a/libmultipath/dict.c b/libmultipath/dict.c |
| 19 | index 7ad0f5a..ab808d6 100644 |
| 20 | --- a/libmultipath/dict.c |
| 21 | +++ b/libmultipath/dict.c |
| 22 | @@ -55,6 +55,21 @@ set_str(vector strvec, void *ptr) |
| 23 | } |
| 24 | |
| 25 | static int |
| 26 | +set_regex(vector strvec, void *ptr) |
| 27 | +{ |
| 28 | + char **str_ptr = (char **)ptr; |
| 29 | + |
| 30 | + if (*str_ptr) |
| 31 | + FREE(*str_ptr); |
| 32 | + *str_ptr = set_regex_value(strvec); |
| 33 | + |
| 34 | + if (!*str_ptr) |
| 35 | + return 1; |
| 36 | + |
| 37 | + return 0; |
| 38 | +} |
| 39 | + |
| 40 | +static int |
| 41 | set_yes_no(vector strvec, void *ptr) |
| 42 | { |
| 43 | char * buff; |
| 44 | @@ -1271,7 +1286,7 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \ |
| 45 | if (!conf->option) \ |
| 46 | return 1; \ |
| 47 | \ |
| 48 | - buff = set_value(strvec); \ |
| 49 | + buff = set_regex_value(strvec); \ |
| 50 | if (!buff) \ |
| 51 | return 1; \ |
| 52 | \ |
| 53 | @@ -1287,7 +1302,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \ |
| 54 | if (!conf->option) \ |
| 55 | return 1; \ |
| 56 | \ |
| 57 | - buff = set_value(strvec); \ |
| 58 | + buff = set_regex_value(strvec); \ |
| 59 | if (!buff) \ |
| 60 | return 1; \ |
| 61 | \ |
| 62 | @@ -1388,16 +1403,16 @@ device_handler(struct config *conf, vector strvec) |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | -declare_hw_handler(vendor, set_str) |
| 67 | +declare_hw_handler(vendor, set_regex) |
| 68 | declare_hw_snprint(vendor, print_str) |
| 69 | |
| 70 | -declare_hw_handler(product, set_str) |
| 71 | +declare_hw_handler(product, set_regex) |
| 72 | declare_hw_snprint(product, print_str) |
| 73 | |
| 74 | -declare_hw_handler(revision, set_str) |
| 75 | +declare_hw_handler(revision, set_regex) |
| 76 | declare_hw_snprint(revision, print_str) |
| 77 | |
| 78 | -declare_hw_handler(bl_product, set_str) |
| 79 | +declare_hw_handler(bl_product, set_regex) |
| 80 | declare_hw_snprint(bl_product, print_str) |
| 81 | |
| 82 | declare_hw_handler(hwhandler, set_str) |
| 83 | diff --git a/libmultipath/parser.c b/libmultipath/parser.c |
| 84 | index b8b7e0d..34b4ad2 100644 |
| 85 | --- a/libmultipath/parser.c |
| 86 | +++ b/libmultipath/parser.c |
| 87 | @@ -380,6 +380,19 @@ set_value(vector strvec) |
| 88 | return alloc; |
| 89 | } |
| 90 | |
| 91 | +void * |
| 92 | +set_regex_value(vector strvec) |
| 93 | +{ |
| 94 | + char *buff = set_value(strvec); |
| 95 | + |
| 96 | + if (buff && strcmp("*", buff) == 0) { |
| 97 | + condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\""); |
| 98 | + FREE(buff); |
| 99 | + return strdup(".*"); |
| 100 | + } |
| 101 | + return buff; |
| 102 | +} |
| 103 | + |
| 104 | /* non-recursive configuration stream handler */ |
| 105 | static int kw_level = 0; |
| 106 | |
| 107 | diff --git a/libmultipath/parser.h b/libmultipath/parser.h |
| 108 | index 62906e9..b791705 100644 |
| 109 | --- a/libmultipath/parser.h |
| 110 | +++ b/libmultipath/parser.h |
| 111 | @@ -77,6 +77,7 @@ extern void dump_keywords(vector keydump, int level); |
| 112 | extern void free_keywords(vector keywords); |
| 113 | extern vector alloc_strvec(char *string); |
| 114 | extern void *set_value(vector strvec); |
| 115 | +extern void *set_regex_value(vector strvec); |
| 116 | extern int process_file(struct config *conf, char *conf_file); |
| 117 | extern struct keyword * find_keyword(vector keywords, vector v, char * name); |
| 118 | int snprint_keyword(char *buff, int len, char *fmt, struct keyword *kw, |
| 119 | -- |
| 120 | 2.7.4 |
| 121 | |