input/Manager: Ignore empty record types

Somewhere record types with zero fields get the optional attribute
apparently. The input/sqlite/basic test failed due to complaining
that ctx is optional. It isn't optional and when it has zero fields
we can just ignore it, too.

Also adds a input framework test with an explicit empty record type
This commit is contained in:
Arne Welzel 2025-06-27 17:28:57 +02:00
parent 8c7d732d4c
commit a975d65d01
4 changed files with 58 additions and 2 deletions

View file

@ -881,13 +881,14 @@ bool Manager::UnrollRecordType(vector<Field*>* fields, const RecordType* rec, co
if ( rec->GetFieldType(i)->Tag() == TYPE_RECORD ) { if ( rec->GetFieldType(i)->Tag() == TYPE_RECORD ) {
string prep = nameprepend + rec->FieldName(i) + "."; string prep = nameprepend + rec->FieldName(i) + ".";
if ( rec->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL) ) { const auto* rt = rec->GetFieldType(i)->AsRecordType();
if ( rt->NumFields() > 0 && rec->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL) ) {
reporter->Info("The input framework does not support optional record fields: \"%s\"", reporter->Info("The input framework does not support optional record fields: \"%s\"",
rec->FieldName(i)); rec->FieldName(i));
return false; return false;
} }
if ( ! UnrollRecordType(fields, rec->GetFieldType(i)->AsRecordType(), prep, allow_file_func) ) { if ( ! UnrollRecordType(fields, rt, prep, allow_file_func) ) {
return false; return false;
} }
} }

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
received termination signal

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
Input::EVENT_NEW, [s=string1, e0=[], r0=[e0=[], c0=4242, c1=4711, e1=[], s=r0s-1], e1=[]]
Input::EVENT_NEW, [s=string2, e0=[], r0=[e0=[], c0=4343, c1=<uninitialized>, e1=[], s=r0s-2], e1=[]]

View file

@ -0,0 +1,50 @@
# @TEST-DOC: Check that empty record types are ignored.
#
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff .stderr
# @TEST-EXEC: btest-diff out
# @TEST-START-FILE input.log
#separator \x09
#path ssh
#fields s r0.c0 r0.c1 r0.s
#types string count string
string1 4242 4711 r0s-1
string2 4343 - r0s-2
# @TEST-END-FILE
redef exit_only_after_terminate = T;
module Test;
type EmptyRec: record { };
type MyRec: record {
e0: EmptyRec; # stuffing
c0: count;
c1: count &optional;
e1: EmptyRec; # stuffing
s: string;
};
type Val: record {
s: string;
e0: EmptyRec; # stuffing
r0: MyRec;
e1: EmptyRec; # stuffing
};
event Test::line(description: Input::EventDescription, tpe: Input::Event, v: Val)
{
print tpe, v;
}
event Input::end_of_data(name: string, source:string)
{
terminate();
}
event zeek_init()
{
Input::add_event([$source="input.log", $name="file", $fields=Val, $ev=Test::line]);
}