diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 223173dbde..cd99395555 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -575,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 @@ -583,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 44b1fcb93f..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 @@ -6,3 +6,6 @@ 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 6e5aa160ae..3785148a73 100644 --- a/testing/btest/scripts/base/frameworks/config/missing-enum-value.zeek +++ b/testing/btest/scripts/base/frameworks/config/missing-enum-value.zeek @@ -6,6 +6,9 @@ @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 @@ -15,6 +18,10 @@ 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"); } @@ -22,5 +29,8 @@ event Input::end_of_data(name: string, source:string) { print mycolors; print nocolors; + print color_vec; + print bad_color_vec; + print no_color_vec; terminate(); }