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

@ -3632,6 +3632,10 @@ Val* cast_value_to_type(Val* v, BroType* t)
if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) )
{
auto dv = v->AsRecordVal()->Lookup(0);
if ( ! dv )
return 0;
return static_cast<bro_broker::DataVal *>(dv)->castTo(t);
}
@ -3654,6 +3658,10 @@ bool can_cast_value_to_type(const Val* v, BroType* t)
if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) )
{
auto dv = v->AsRecordVal()->Lookup(0);
if ( ! dv )
return false;
return static_cast<const bro_broker::DataVal *>(dv)->canCastTo(t);
}