Fix seg fault on trying to type-cast invalid/nil Broker::Data

This situation now throws a runtime expression exception instead of
crashing on null pointer access.
This commit is contained in:
Jon Siwek 2018-08-15 11:00:20 -05:00
parent 0e6913fba0
commit f336c8c710
6 changed files with 28 additions and 4 deletions

View file

@ -16,6 +16,8 @@
#include "Trigger.h"
#include "IPAddr.h"
#include "broker/Data.h"
const char* expr_name(BroExprTag t)
{
static const char* expr_names[int(NUM_EXPRS)] = {
@ -5503,11 +5505,16 @@ Val* CastExpr::Eval(Frame* f) const
}
ODesc d;
d.Add("cannot cast value of type '");
d.Add("invalid cast of value with type '");
v->Type()->Describe(&d);
d.Add("' to type '");
Type()->Describe(&d);
d.Add("'");
if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) &&
! v->AsRecordVal()->Lookup(0) )
d.Add(" (nil $data field)");
Unref(v);
reporter->ExprRuntimeError(this, "%s", d.Description());
return 0; // not reached.