logging/Manager: Fix crash for rotation format function not returning

While working on a rotation format function, ran into Zeek crashing
when not returning a value from it, fix and recover the same way as
for scripting errors.
This commit is contained in:
Arne Welzel 2023-04-05 16:00:43 +02:00
parent 6ac72a31bf
commit a5e7faf564
5 changed files with 77 additions and 5 deletions

View file

@ -1561,10 +1561,19 @@ std::string Manager::FormatRotationPath(EnumValPtr writer, std::string_view path
ri->Assign<FuncVal>(5, std::move(postprocessor));
std::string rval;
ValPtr res = Val::nil;
try
{
auto res = rotation_format_func->Invoke(ri);
res = rotation_format_func->Invoke(ri);
}
catch ( InterpreterException& e )
{
// Will have logged something, res continues to be nil
}
if ( res )
{
auto rp_val = res->AsRecordVal();
auto dir_val = rp_val->GetFieldOrDefault(0);
auto prefix = rp_val->GetFieldAs<StringVal>(1)->CheckString();
@ -1590,7 +1599,7 @@ std::string Manager::FormatRotationPath(EnumValPtr writer, std::string_view path
else
rval = util::fmt("%s/%s", dir, prefix);
}
catch ( InterpreterException& e )
else
{
auto rot_str = format_rotation_time_fallback((time_t)open);
rval = util::fmt("%.*s-%s", static_cast<int>(path.size()), path.data(), rot_str.data());