From dd59c480341321b06c5fcc94874123cfc8bae822 Mon Sep 17 00:00:00 2001 From: Gianmatteo Palmieri Date: Mon, 15 Apr 2024 14:48:49 +0200 Subject: [PATCH] new(engine): raise warning instead of error on invalid macro/list name Signed-off-by: Gianmatteo Palmieri --- userspace/engine/falco_load_result.cpp | 12 +++++++++--- userspace/engine/falco_load_result.h | 4 +++- userspace/engine/rule_loader_reader.cpp | 10 ++++++++-- userspace/engine/rule_loading_messages.h | 4 ---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/userspace/engine/falco_load_result.cpp b/userspace/engine/falco_load_result.cpp index 76c859c8..102e5ab7 100644 --- a/userspace/engine/falco_load_result.cpp +++ b/userspace/engine/falco_load_result.cpp @@ -73,7 +73,9 @@ static const std::string warning_codes[] = { "LOAD_DEPRECATED_ITEM", "LOAD_WARNING_EXTENSION", "LOAD_APPEND_NO_VALUES", - "LOAD_EXCEPTION_NAME_NOT_UNIQUE" + "LOAD_EXCEPTION_NAME_NOT_UNIQUE", + "LOAD_INVALID_MACRO_NAME", + "LOAD_INVALID_LIST_NAME" }; const std::string& falco::load_result::warning_code_str(warning_code wc) @@ -92,7 +94,9 @@ static const std::string warning_strings[] = { "Used deprecated item", "Warning in extension item", "Overriding/appending with no values", - "Multiple exceptions defined with the same name" + "Multiple exceptions defined with the same name", + "Invalid macro name", + "Invalid list name" }; const std::string& falco::load_result::warning_str(warning_code wc) @@ -111,7 +115,9 @@ static const std::string warning_descs[] = { "A deprecated item is employed by lists, macros, or rules.", "An extension item has a warning", "A rule exception is overriding/appending with no values", - "A rule is defining multiple exceptions with the same name" + "A rule is defining multiple exceptions with the same name", + "A macro is defined with an invalid name", + "A list is defined with an invalid name" }; const std::string& falco::load_result::warning_desc(warning_code wc) diff --git a/userspace/engine/falco_load_result.h b/userspace/engine/falco_load_result.h index 79db7349..1d193dcb 100644 --- a/userspace/engine/falco_load_result.h +++ b/userspace/engine/falco_load_result.h @@ -59,7 +59,9 @@ public: LOAD_DEPRECATED_ITEM, LOAD_WARNING_EXTENSION, LOAD_APPEND_NO_VALUES, - LOAD_EXCEPTION_NAME_NOT_UNIQUE + LOAD_EXCEPTION_NAME_NOT_UNIQUE, + LOAD_INVALID_MACRO_NAME, + LOAD_INVALID_LIST_NAME }; virtual ~load_result() = default; diff --git a/userspace/engine/rule_loader_reader.cpp b/userspace/engine/rule_loader_reader.cpp index df32715d..e0b134b1 100644 --- a/userspace/engine/rule_loader_reader.cpp +++ b/userspace/engine/rule_loader_reader.cpp @@ -471,7 +471,10 @@ void rule_loader::reader::read_item( rule_loader::context ctx(item, rule_loader::context::LIST, name, parent); bool invalid_name = !re2::RE2::FullMatch(name, s_rgx_barestr); - THROW(invalid_name, ERROR_INVALID_LIST_NAME RGX_BARESTR, ctx); + if(invalid_name) + { + cfg.res->add_warning(falco::load_result::LOAD_INVALID_LIST_NAME, "List has an invalid name. List names must match a regular expression: " RGX_BARESTR, ctx); + } rule_loader::list_info v(ctx); @@ -515,7 +518,10 @@ void rule_loader::reader::read_item( rule_loader::context ctx(item, rule_loader::context::MACRO, name, parent); bool invalid_name = !re2::RE2::FullMatch(name, s_rgx_identifier); - THROW(invalid_name, ERROR_INVALID_MACRO_NAME RGX_IDENTIFIER, ctx); + if(invalid_name) + { + cfg.res->add_warning(falco::load_result::LOAD_INVALID_MACRO_NAME, "Macro has an invalid name. Macro names must match a regular expression: " RGX_IDENTIFIER, ctx); + } rule_loader::macro_info v(ctx); v.name = name; diff --git a/userspace/engine/rule_loading_messages.h b/userspace/engine/rule_loading_messages.h index 576cb2b2..5962fb0a 100644 --- a/userspace/engine/rule_loading_messages.h +++ b/userspace/engine/rule_loading_messages.h @@ -21,7 +21,3 @@ #define ERROR_NO_PREVIOUS_RULE_APPEND "Rule uses 'append' or 'override.: append' but no rule by that name already exists" #define ERROR_NO_PREVIOUS_RULE_REPLACE "An 'override.: replace' to a rule was requested but no rule by that name already exists" - -#define ERROR_INVALID_MACRO_NAME "Macro has an invalid name. Macro names must match a regular expression: " - -#define ERROR_INVALID_LIST_NAME "List has an invalid name. List names must match a regular expression: "