GH-591: fix reading set[enum] values from input files

This commit is contained in:
Jon Siwek 2019-10-02 21:03:30 -07:00
parent 8ba19cd7d1
commit fd66e7b9f6
4 changed files with 93 additions and 2 deletions

View file

@ -2536,8 +2536,31 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co
if ( stag == TYPE_VOID )
TypeTag stag = val->val.set_val.vals[0]->type;
set_index = new TypeList(base_type(stag)->Ref());
set_index->Append(base_type(stag)->Ref());
BroType* index_type;
if ( stag == TYPE_ENUM )
{
// Enums are not a base-type, so need to look it up.
const auto& sv = val->val.set_val.vals[0]->val.string_val;
std::string enum_name(sv.data, sv.length);
auto enum_id = global_scope()->Lookup(enum_name);
if ( ! enum_id )
{
Warning(i, "Value '%s' for stream '%s' is not a valid enum.",
enum_name.data(), i->name.c_str());
have_error = true;
return nullptr;
}
index_type = enum_id->Type()->AsEnumType();
}
else
index_type = base_type_no_ref(stag);
set_index = new TypeList(index_type);
set_index->Append(index_type->Ref());
}
SetType* s = new SetType(set_index, 0);

View file

@ -0,0 +1,12 @@
DPD::ignore_violations, {
}
---
{
Analyzer::ANALYZER_SYSLOG
}
---
DPD::ignore_violations, {
Analyzer::ANALYZER_SYSLOG
}
---

View file

@ -0,0 +1,10 @@
#separator \x09
#set_separator ,
#empty_field (empty)
#unset_field -
#path config
#open 2019-10-03-04-02-02
#fields ts id old_value new_value location
#types time string string string string
1570075321.966826 DPD::ignore_violations (empty) Analyzer::ANALYZER_SYSLOG -
#close 2019-10-03-04-02-02

View file

@ -0,0 +1,46 @@
# @TEST-EXEC: btest-bg-run zeek zeek -b %INPUT
# @TEST-EXEC: btest-bg-wait 10
# @TEST-EXEC: btest-diff zeek/.stdout
# @TEST-EXEC: btest-diff zeek/config.log
@TEST-START-FILE configfile4
DPD::ignore_violations Analyzer::ANALYZER_SYSLOG
@TEST-END-FILE
@load base/frameworks/config
@load base/frameworks/dpd
redef exit_only_after_terminate = T;
redef InputConfig::empty_field = "EMPTY";
redef InputConfig::set_separator = "\t";
type Idx: record {
option_name: string;
};
type Val: record {
option_val: string;
};
global currconfig: table[string] of string = table();
event InputConfig::new_value(name: string, source: string, id: string, value: any)
{
print id, lookup_ID(id);
print "---";
print value;
print "---";
Config::set_value(id, value);
print id, lookup_ID(id);
print "---";
}
event Input::end_of_data(name: string, source:string)
{
terminate();
}
event zeek_init()
{
Input::add_table([$reader=Input::READER_CONFIG, $source="../configfile4", $name="configuration", $idx=Idx, $val=Val, $destination=currconfig, $want_record=F]);
}