diff --git a/CHANGES b/CHANGES index c5488fb9de..e0df5f363b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,10 @@ +4.1.0-dev.641 | 2021-05-17 11:28:11 -0700 + + * GH-1558: Fix reading `vector of enum` types from config files (Jon Siwek, Corelight) + + * GH-1555: Fix reading empty set[enum] values from config files (Jon Siwek, Corelight) + 4.1.0-dev.638 | 2021-05-17 13:08:28 +0100 * Manual page updates (Henrik Kramselund Jereminsen) diff --git a/VERSION b/VERSION index d944358ec1..3c557cdf0f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0-dev.638 +4.1.0-dev.641 diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 2804706489..cd99395555 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -519,7 +519,8 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e case TYPE_TABLE: { TypeListPtr set_index; - if ( val->val.set_val.size == 0 && val->subtype == TYPE_VOID ) + if ( val->val.set_val.size == 0 && + ( val->subtype == TYPE_VOID || val->subtype == TYPE_ENUM ) ) // don't know type - unspecified table. set_index = make_intrusive(); else @@ -574,7 +575,8 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e { TypePtr type; - if ( val->val.vector_val.size == 0 && val->subtype == TYPE_VOID ) + if ( val->val.vector_val.size == 0 && + ( val->subtype == TYPE_VOID || val->subtype == TYPE_ENUM ) ) // don't know type - unspecified table. type = base_type(TYPE_ANY); else @@ -582,6 +584,24 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e // all entries have to have the same type... if ( val->subtype == TYPE_VOID ) type = base_type(val->val.vector_val.vals[0]->type); + else if ( val->subtype == TYPE_ENUM ) + { + // Enums are not a base-type, so need to look it up. + const auto& sv = val->val.vector_val.vals[0]->val.string_val; + std::string enum_name(sv.data, sv.length); + const auto& enum_id = detail::global_scope()->Find(enum_name); + + if ( ! enum_id ) + { + reporter->Warning("Value '%s' of source '%s' is not a valid enum.", + enum_name.data(), source.c_str()); + + have_error = true; + return nullptr; + } + + type = enum_id->GetType(); + } else type = base_type(val->subtype); } diff --git a/testing/btest/Baseline/scripts.base.frameworks.config.missing-enum-value/zeek..stderr b/testing/btest/Baseline/scripts.base.frameworks.config.missing-enum-value/zeek..stderr index bb65f36198..7bbc3a37c1 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.config.missing-enum-value/zeek..stderr +++ b/testing/btest/Baseline/scripts.base.frameworks.config.missing-enum-value/zeek..stderr @@ -1,3 +1,5 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. warning: Value 'asdf' for source 'thread ../configfile/Input::READER_CONFIG' is not a valid enum. error: SendEvent for event InputConfig::new_value failed +warning: Value '1234' for source 'thread ../configfile/Input::READER_CONFIG' is not a valid enum. +error: SendEvent for event InputConfig::new_value failed diff --git a/testing/btest/Baseline/scripts.base.frameworks.config.missing-enum-value/zeek..stdout b/testing/btest/Baseline/scripts.base.frameworks.config.missing-enum-value/zeek..stdout index c59a7a14f2..cbeb31cbc9 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.config.missing-enum-value/zeek..stdout +++ b/testing/btest/Baseline/scripts.base.frameworks.config.missing-enum-value/zeek..stdout @@ -3,3 +3,9 @@ Red, Green } +{ + +} +[Green] +[Red] +[] diff --git a/testing/btest/scripts/base/frameworks/config/missing-enum-value.zeek b/testing/btest/scripts/base/frameworks/config/missing-enum-value.zeek index ce1bb0c0ed..3785148a73 100644 --- a/testing/btest/scripts/base/frameworks/config/missing-enum-value.zeek +++ b/testing/btest/scripts/base/frameworks/config/missing-enum-value.zeek @@ -5,6 +5,10 @@ @TEST-START-FILE configfile mycolors Red,asdf,Blue +nocolors +color_vec Green +bad_color_vec Green,1234,Blue +no_color_vec @TEST-END-FILE @load base/frameworks/config @@ -12,9 +16,21 @@ mycolors Red,asdf,Blue type Color: enum { Red, Green, Blue, }; option mycolors = set(Red, Green); +option nocolors = set(Red, Green); + +option color_vec: vector of Color = { Red }; +option bad_color_vec: vector of Color = { Red }; +option no_color_vec: vector of Color = { Red }; event zeek_init() { Config::read_config("../configfile"); } event Input::end_of_data(name: string, source:string) - { print mycolors; terminate(); } \ No newline at end of file + { + print mycolors; + print nocolors; + print color_vec; + print bad_color_vec; + print no_color_vec; + terminate(); + }