input: Add location info for invalid enums

Fixes #2613
This commit is contained in:
Arne Welzel 2022-11-29 12:12:55 +01:00
parent 0e97c29eb8
commit e5d9a715ce
4 changed files with 15 additions and 3 deletions

View file

@ -2417,8 +2417,16 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, Type* request_type,
zeek_int_t index = request_type->AsEnumType()->Lookup(module, var.c_str());
if ( index == -1 )
{
Warning(i, "Value '%s' for stream '%s' is not a valid enum.", enum_string.c_str(),
i->name.c_str());
auto source = i->reader->Info().source;
auto file_pos = val->GetFileLineNumber();
const char* warning = zeek::util::fmt(
"Value '%s' for stream '%s' is not a valid enum.", enum_string.c_str(),
i->name.c_str());
if ( source && file_pos != -1 )
Warning(i, "%s, line %d: %s", source, file_pos, warning);
else
Warning(i, "%s", warning);
have_error = true;
return nullptr;

View file

@ -5,6 +5,8 @@ error: ../input.log/Input::READER_ASCII: ../input.log, line 5: Init failed
error: ../input.log/Input::READER_ASCII: ../input.log, line 5: Not enough fields in line 'T -41 SSH::LOG 21 123 tcp 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30' of ../input.log. Found 15 fields, want positions 17 and -1
error: ../input.log/Input::READER_ASCII: ../input.log, line 5: terminating thread
received termination signal
warning: ../input.log, line 10: Value 'EMPTY' for stream 'ssh' is not a valid enum.
warning: ../input.log, line 11: Value '' for stream 'ssh' is not a valid enum.
warning: ../input.log/Input::READER_ASCII: ../input.log, line 5: Not enough fields in line 'T -41 SSH::LOG 21 123 tcp 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30' of ../input.log. Found 15 fields, want positions 17 and -1
warning: ../input.log/Input::READER_ASCII: ../input.log, line 7: Tried to parse invalid/unknown protocol: whatever
warning: ../input.log/Input::READER_ASCII: ../input.log, line 8: Bad address: 342.2.3.4

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning: Value 'IdoNot::Exist' for stream 'enum' is not a valid enum.
warning: ../input.log, line 2: Value 'IdoNot::Exist' for stream 'enum' is not a valid enum.
received termination signal

View file

@ -17,6 +17,8 @@ T -42 SSH::LOG 21 123 tcp 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000
T -43 SSH::LOG 21 123 whatever 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY 4242 HOHOHO
T -44 SSH::LOG 21 123 udp 10.0.0.0/24 342.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY 4242 HOHOHO
T -41
T -41 EMPTY 21 123 tcp 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY 4242
T -41 21 123 tcp 10.0.0.0/24 1.2.3.4 3.14 1315801931.273616 100.000000 hurz 2,4,1,3 CC,AA,BB EMPTY 10,20,30 EMPTY 4242
@TEST-END-FILE
@load base/protocols/ssh