diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 09b2b0cff3..7b27638a0e 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1059,19 +1059,33 @@ Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const RecordType } else { - auto* l = new ListVal(TYPE_ANY); + auto l = make_intrusive(TYPE_ANY); for ( int j = 0 ; j < type->NumFields(); j++ ) { if ( type->GetFieldType(j)->Tag() == TYPE_RECORD ) - l->Append({AdoptRef{}, ValueToRecordVal(i, vals, - type->GetFieldType(j)->AsRecordType(), &position, have_error)}); + { + auto rv = ValueToRecordVal(i, vals, type->GetFieldType(j)->AsRecordType(), + &position, have_error); + if ( have_error ) + break; + + l->Append({AdoptRef{}, rv}); + } else { - l->Append({AdoptRef{}, ValueToVal(i, vals[position], type->GetFieldType(j).get(), have_error)}); + auto v = ValueToVal(i, vals[position], type->GetFieldType(j).get(), have_error); + if ( have_error ) + break; + + l->Append({AdoptRef{}, v}); position++; } } - idxval = l; + + if ( have_error ) + return nullptr; + + idxval = l.release(); } assert ( position == num_fields ); @@ -1500,8 +1514,10 @@ int Manager::SendEventStreamEvent(Stream* i, EnumVal* type, const Value* const * if ( stream->want_record ) { - RecordVal * r = ValueToRecordVal(i, vals, stream->fields, &position, convert_error); - out_vals.push_back(r); + RecordVal* r = ValueToRecordVal(i, vals, stream->fields, &position, convert_error); + + if ( ! convert_error ) + out_vals.push_back(r); } else @@ -1521,6 +1537,9 @@ int Manager::SendEventStreamEvent(Stream* i, EnumVal* type, const Value* const * position++; } + if ( convert_error) + break; + out_vals.push_back(val); } } @@ -1883,7 +1902,7 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v { assert(position != nullptr); // we need the pointer to point to data. - auto* rec = new RecordVal({NewRef{}, request_type}); + auto rec = make_intrusive(RecordTypePtr{NewRef{}, request_type}); for ( int i = 0; i < request_type->NumFields(); i++ ) { Val* fieldVal = nullptr; @@ -1907,11 +1926,13 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v (*position)++; } - if ( fieldVal ) + if ( have_error ) + return nullptr; + else if ( fieldVal ) rec->Assign(i, {AdoptRef{}, fieldVal}); } - return rec; + return rec.release(); } // Count the length of the values used to create a correct length buffer for @@ -2287,15 +2308,18 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, Type* request_type, auto set_index = make_intrusive(type); set_index->Append(type); auto s = make_intrusive(std::move(set_index), nullptr); - auto* t = new TableVal(std::move(s)); + auto t = make_intrusive(std::move(s)); for ( int j = 0; j < val->val.set_val.size; j++ ) { Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error); + if ( have_error ) + return nullptr; + t->Assign({AdoptRef{}, assignval}, nullptr); } - return t; + return t.release(); } case TYPE_VECTOR: @@ -2308,6 +2332,10 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, Type* request_type, for ( int j = 0; j < val->val.vector_val.size; j++ ) { auto el = ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error); + + if ( have_error ) + return nullptr; + v->Assign(j, {AdoptRef{}, el}); } diff --git a/testing/btest/Baseline/scripts.base.frameworks.input.missing-table-value/zeek..stderr b/testing/btest/Baseline/scripts.base.frameworks.input.missing-table-value/zeek..stderr new file mode 100644 index 0000000000..8772cd193c --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.input.missing-table-value/zeek..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. +warning: Value 'asdf' for stream 'denylist' is not a valid enum. diff --git a/testing/btest/Baseline/scripts.base.frameworks.input.missing-table-value/zeek..stdout b/testing/btest/Baseline/scripts.base.frameworks.input.missing-table-value/zeek..stdout new file mode 100644 index 0000000000..96181eeeda --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.input.missing-table-value/zeek..stdout @@ -0,0 +1,10 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +{ +[192.168.17.1] = [colors={ +Red, +White +}], +[192.168.250.3] = [colors={ +Blue +}] +} diff --git a/testing/btest/scripts/base/frameworks/input/missing-table-value.zeek b/testing/btest/scripts/base/frameworks/input/missing-table-value.zeek new file mode 100644 index 0000000000..9091b02501 --- /dev/null +++ b/testing/btest/scripts/base/frameworks/input/missing-table-value.zeek @@ -0,0 +1,35 @@ +# @TEST-EXEC: btest-bg-run zeek zeek -b %INPUT +# @TEST-EXEC: btest-bg-wait 10 +# @TEST-EXEC: btest-diff zeek/.stderr +# @TEST-EXEC: btest-diff zeek/.stdout + +@TEST-START-FILE denylist.txt +#separator \x09 +#fields ip colors +192.168.17.1 Red,White +192.168.27.2 White,asdf +192.168.250.3 Blue +@TEST-END-FILE + +# test.zeek +type Idx: record { + ip: addr; +}; + +type Color: enum { Red, White, Blue, }; + +type Val: record { + colors: set[Color]; +}; + +global denylist: table[addr] of Val = table(); + +event zeek_init() { + Input::add_table([$source="../denylist.txt", $name="denylist", + $idx=Idx, $val=Val, $destination=denylist]); + Input::remove("denylist"); +} + +event Input::end_of_data(name: string, source: string) { + print denylist; +} \ No newline at end of file