Skip to content

Commit

Permalink
fix(userspace): handle exceptions for process_k8s_audit_event
Browse files Browse the repository at this point in the history
This fix has two major points in it:

- when `std::stoll` is used in parse_as_int64 handle all the exceptions it
can throw (https://en.cppreference.com/w/cpp/string/basic_string/stol)
- when `process_k8s_audit_event` an eventual exception in it does not
stop the webserver process. This is done by doing a catch all handle
outside it and by logging an error message to the caller as well as in
stderr

Signed-off-by: Lorenzo Fontana <lo@linux.com>
  • Loading branch information
fntlnz authored and poiana committed Apr 19, 2021
1 parent 8b0d22d commit 46425b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion userspace/engine/json_evt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ bool json_event_value::parse_as_int64(int64_t &intval, const std::string &val)
return false;
}
}
catch (std::invalid_argument &e)
catch(std::out_of_range &)
{
return false;
}
catch (std::invalid_argument &)
{
return false;
}
Expand Down
12 changes: 11 additions & 1 deletion userspace/falco/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ bool k8s_audit_handler::accept_data(falco_engine *engine,
for(auto &jev : jevts)
{
std::unique_ptr<falco_engine::rule_result> res;
res = engine->process_k8s_audit_event(&jev);

try
{
res = engine->process_k8s_audit_event(&jev);
}
catch(...)
{
errstr = string("unkown error processing audit event");
fprintf(stderr, "%s\n", errstr.c_str());
return false;
}

if(res)
{
Expand Down

0 comments on commit 46425b3

Please sign in to comment.