GH-1819: Handle recursive types when describing type in binary mode

This commit is contained in:
Tim Wojtulewicz 2021-11-08 15:19:57 -07:00
parent c190c85bf0
commit e0b116154a
2 changed files with 29 additions and 2 deletions

View file

@ -1326,10 +1326,15 @@ void RecordType::DescribeFields(ODesc* d) const
d->AddCount(types->length()); d->AddCount(types->length());
for ( const auto& type : *types ) for ( const auto& type : *types )
{ {
type->type->Describe(d);
d->SP();
d->Add(type->id); d->Add(type->id);
d->SP(); d->SP();
if ( d->FindType(type->type.get()) )
d->Add("<recursion>");
else
type->type->Describe(d);
d->SP();
} }
} }
} }

View file

@ -0,0 +1,22 @@
# @TEST-EXEC: zeek -b %INPUT
# global_ids() here contains some types that are recursive, in that
# arguments to functions contain chained references to the type that
# defines the function. This tests that we don't crash when
# attempting to call Describe() on those types in binary-mode.
event zeek_init()
{
local sh: string = "";
local gi = global_ids();
for (myfunc in gi)
{
if(gi[myfunc]?$value)
{
if(strstr(myfunc,"lambda") > 0)
{
sh = sha256_hash(gi[myfunc]$value);
print(sh);
}
}
}
}