diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 94eae7490c..c8cc34ee1f 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -881,13 +881,14 @@ bool Manager::UnrollRecordType(vector* fields, const RecordType* rec, co if ( rec->GetFieldType(i)->Tag() == TYPE_RECORD ) { 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\"", rec->FieldName(i)); return false; } - if ( ! UnrollRecordType(fields, rec->GetFieldType(i)->AsRecordType(), prep, allow_file_func) ) { + if ( ! UnrollRecordType(fields, rt, prep, allow_file_func) ) { return false; } } diff --git a/testing/btest/Baseline/scripts.base.frameworks.input.empty-nested-record/.stderr b/testing/btest/Baseline/scripts.base.frameworks.input.empty-nested-record/.stderr new file mode 100644 index 0000000000..e3f6131b1d --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.input.empty-nested-record/.stderr @@ -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 diff --git a/testing/btest/Baseline/scripts.base.frameworks.input.empty-nested-record/out b/testing/btest/Baseline/scripts.base.frameworks.input.empty-nested-record/out new file mode 100644 index 0000000000..6c6f35d094 --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.input.empty-nested-record/out @@ -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=, e1=[], s=r0s-2], e1=[]] diff --git a/testing/btest/scripts/base/frameworks/input/empty-nested-record.zeek b/testing/btest/scripts/base/frameworks/input/empty-nested-record.zeek new file mode 100644 index 0000000000..1da0dd00dd --- /dev/null +++ b/testing/btest/scripts/base/frameworks/input/empty-nested-record.zeek @@ -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]); + }