mirror of
https://github.com/zeek/zeek.git
synced 2025-10-15 21:18:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/gh-1555-gh-1558-config-enum-fixes'
* origin/topic/jsiwek/gh-1555-gh-1558-config-enum-fixes: GH-1558: Fix reading `vector of enum` types from config files GH-1555: Fix reading empty set[enum] values from config files
This commit is contained in:
commit
31f73f6e92
6 changed files with 54 additions and 4 deletions
6
CHANGES
6
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)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
4.1.0-dev.638
|
||||
4.1.0-dev.641
|
||||
|
|
|
@ -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<TypeList>();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,3 +3,9 @@
|
|||
Red,
|
||||
Green
|
||||
}
|
||||
{
|
||||
|
||||
}
|
||||
[Green]
|
||||
[Red]
|
||||
[]
|
||||
|
|
|
@ -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(); }
|
||||
{
|
||||
print mycolors;
|
||||
print nocolors;
|
||||
print color_vec;
|
||||
print bad_color_vec;
|
||||
print no_color_vec;
|
||||
terminate();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue