Skip to content

Commit

Permalink
new(engine): raise warning instead of error on invalid macro/list name
Browse files Browse the repository at this point in the history
Signed-off-by: Gianmatteo Palmieri <[email protected]>
  • Loading branch information
mrgian authored and poiana committed Apr 17, 2024
1 parent e21a3a5 commit dd59c48
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
12 changes: 9 additions & 3 deletions userspace/engine/falco_load_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion userspace/engine/falco_load_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class load_result {
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;
Expand Down
10 changes: 8 additions & 2 deletions userspace/engine/rule_loader_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions userspace/engine/rule_loading_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@
#define ERROR_NO_PREVIOUS_RULE_APPEND "Rule uses 'append' or 'override.<key>: append' but no rule by that name already exists"

#define ERROR_NO_PREVIOUS_RULE_REPLACE "An 'override.<key>: 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: "

0 comments on commit dd59c48

Please sign in to comment.