Skip to content

Commit

Permalink
Handle rule patterns that are invalid regexes (#636)
Browse files Browse the repository at this point in the history
In the case where a rule name can't be compiled as a regex, fall back to
a substring search instead.
  • Loading branch information
mstemm authored and leodido committed May 31, 2019
1 parent 9d107b1 commit d6900e2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions userspace/engine/ruleset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,16 @@ void falco_ruleset::add(string &name,

void falco_ruleset::enable(const string &pattern, bool enabled, uint16_t ruleset)
{
regex re(pattern);
regex re;
bool match_using_regex = true;

try {
re.assign(pattern);
}
catch (std::regex_error e)
{
match_using_regex = false;
}

while (m_rulesets.size() < (size_t) ruleset + 1)
{
Expand All @@ -185,7 +194,16 @@ void falco_ruleset::enable(const string &pattern, bool enabled, uint16_t ruleset

for(const auto &val : m_filters)
{
if (regex_match(val.first, re))
bool matches;
if(match_using_regex)
{
matches = regex_match(val.first, re);
}
else
{
matches = (val.first.find(pattern) != string::npos);
}
if (matches)
{
if(enabled)
{
Expand Down

0 comments on commit d6900e2

Please sign in to comment.