mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/gh-1024-broker-store-handle-type-checks'
* origin/topic/jsiwek/gh-1024-broker-store-handle-type-checks: Improve Broker store API's handling of invalid arguments Add builtin_exception() functions GH-1024: fix crash on passing wrong types to Broker store API This was a bit of a bigger merge since Zeek changed inbetween the time of the PR and me actually merging it. I put the new functions into the zeek::detail namespace -- since it seems unlikely that those will be used by something external. I also renamed them to fit better with the naming scheme of the new error functions. Fixes GH-1024
This commit is contained in:
commit
da2c968ba0
7 changed files with 243 additions and 116 deletions
85
src/Func.cc
85
src/Func.cc
|
@ -788,31 +788,51 @@ function_ingredients::function_ingredients(zeek::detail::ScopePtr scope, zeek::d
|
|||
this->body = std::move(body);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
void emit_builtin_error(const char* msg)
|
||||
{
|
||||
emit_builtin_error(msg, zeek::ValPtr{});
|
||||
}
|
||||
|
||||
void emit_builtin_error(const char* msg, zeek::ValPtr arg)
|
||||
{
|
||||
emit_builtin_error(msg, arg.get());
|
||||
}
|
||||
|
||||
void emit_builtin_error(const char* msg, Obj* arg)
|
||||
static void emit_builtin_error_common(const char* msg, Obj* arg, bool unwind)
|
||||
{
|
||||
auto emit = [=](const zeek::detail::CallExpr* ce)
|
||||
{
|
||||
if ( ce )
|
||||
ce->Error(msg, arg);
|
||||
{
|
||||
if ( unwind )
|
||||
{
|
||||
if ( arg )
|
||||
{
|
||||
ODesc d;
|
||||
arg->Describe(&d);
|
||||
reporter->ExprRuntimeError(ce, "%s (%s), during call:", msg,
|
||||
d.Description());
|
||||
}
|
||||
else
|
||||
reporter->ExprRuntimeError(ce, "%s", msg);
|
||||
}
|
||||
else
|
||||
ce->Error(msg, arg);
|
||||
}
|
||||
else
|
||||
reporter->Error(msg, arg);
|
||||
{
|
||||
if ( arg )
|
||||
{
|
||||
if ( unwind )
|
||||
reporter->RuntimeError(arg->GetLocationInfo(), "%s", msg);
|
||||
else
|
||||
arg->Error(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( unwind )
|
||||
reporter->RuntimeError(nullptr, "%s", msg);
|
||||
else
|
||||
reporter->Error("%s", msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if ( zeek::detail::call_stack.empty() )
|
||||
{
|
||||
// Shouldn't happen unless someone (mistakenly) calls builtin_error()
|
||||
// from somewhere that's not even evaluating script-code.
|
||||
emit(nullptr);
|
||||
return;
|
||||
}
|
||||
|
@ -866,6 +886,39 @@ void emit_builtin_error(const char* msg, Obj* arg)
|
|||
emit(last_call.call);
|
||||
}
|
||||
|
||||
void emit_builtin_exception(const char* msg)
|
||||
{
|
||||
emit_builtin_error_common(msg, nullptr, true);
|
||||
}
|
||||
|
||||
void emit_builtin_exception(const char* msg, const zeek::ValPtr& arg)
|
||||
{
|
||||
emit_builtin_error_common(msg, arg.get(), true);
|
||||
}
|
||||
|
||||
void emit_builtin_exception(const char* msg, Obj* arg)
|
||||
{
|
||||
emit_builtin_error_common(msg, arg, true);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
void emit_builtin_error(const char* msg)
|
||||
{
|
||||
zeek::detail::emit_builtin_error_common(msg, nullptr, false);
|
||||
}
|
||||
|
||||
void emit_builtin_error(const char* msg, const zeek::ValPtr& arg)
|
||||
{
|
||||
zeek::detail::emit_builtin_error_common(msg, arg.get(), false);
|
||||
}
|
||||
|
||||
void emit_builtin_error(const char* msg, Obj* arg)
|
||||
{
|
||||
zeek::detail::emit_builtin_error_common(msg, arg, false);
|
||||
}
|
||||
|
||||
} // namespace zeek
|
||||
|
||||
void builtin_error(const char* msg)
|
||||
|
@ -873,7 +926,7 @@ void builtin_error(const char* msg)
|
|||
zeek::emit_builtin_error(msg);
|
||||
}
|
||||
|
||||
void builtin_error(const char* msg, zeek::ValPtr arg)
|
||||
void builtin_error(const char* msg, const zeek::ValPtr& arg)
|
||||
{
|
||||
zeek::emit_builtin_error(msg, arg);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue