From: Shawn Turner (shaturne) Date: Fri, 20 Jan 2017 18:14:53 +0000 (-0500) Subject: Merge pull request #783 in SNORT/snort3 from lua_lists to master X-Git-Tag: 3.0.0-233~104 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a3276816bdf5890641d355ef694eb8903ad13cf2;p=thirdparty%2Fsnort3.git Merge pull request #783 in SNORT/snort3 from lua_lists to master Squashed commit of the following: commit 45d53c105a64464e1eb44335252985b1b430d4e2 Author: Carter Waxman Date: Thu Jan 19 12:50:48 2017 -0500 added logic to ensure set fails when the module is a list type and a value is set at the top level --- diff --git a/src/framework/module.cc b/src/framework/module.cc index cf237e69c..134ae02f5 100644 --- a/src/framework/module.cc +++ b/src/framework/module.cc @@ -138,6 +138,26 @@ void Module::reset_stats() counts[i] = 0; } +bool Module::verified_begin(const char* fqn, int idx, SnortConfig* c) +{ + table_level++; + return begin(fqn, idx, c); +} + +bool Module::verified_set(const char* fqn, Value& v, SnortConfig* c) +{ + if ( list and table_level < 2 ) + return false; + + return set(fqn, v, c); +} + +bool Module::verified_end(const char* fqn, int idx, SnortConfig* c) +{ + table_level--; + return end(fqn, idx, c); +} + const PegInfo simple_pegs[] = { { "packets", "total packets" }, diff --git a/src/framework/module.h b/src/framework/module.h index 341cd0eee..07c32ac22 100644 --- a/src/framework/module.h +++ b/src/framework/module.h @@ -153,6 +153,11 @@ public: virtual void show_stats(); virtual void reset_stats(); + // Wrappers to check that lists are not tables + bool verified_begin(const char*, int, SnortConfig*); + bool verified_set(const char*, Value&, SnortConfig*); + bool verified_end(const char*, int, SnortConfig*); + protected: Module(const char* name, const char* help); Module(const char* name, const char* help, const Parameter*, @@ -171,6 +176,7 @@ private: const Parameter* params; const Parameter* default_params = nullptr; bool list; + int table_level = 0; Trace* trace; }; diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 7b604e36a..bed9f9380 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -403,7 +403,7 @@ static bool set_var(const char* fqn, Value& val) static bool set_param(Module* mod, const char* fqn, Value& val) { - if ( !mod->set(fqn, val, s_config) ) + if ( !mod->verified_set(fqn, val, s_config) ) { ParseError("%s is invalid", fqn); ++s_errors; @@ -525,7 +525,7 @@ static bool begin(Module* m, const Parameter* p, const char* s, int idx, int dep (idx and p->type != Parameter::PT_LIST) ) { //printf("begin %s %d\n", s, idx); - if ( !m->begin(s, idx, s_config) ) + if ( !m->verified_begin(s, idx, s_config) ) return false; } // don't set list defaults @@ -626,7 +626,7 @@ static bool end(Module* m, const Parameter* p, const char* s, int idx) (idx and p->type != Parameter::PT_LIST) ) { //printf("end %s %d\n", s, idx); - return m->end(s, idx, s_config); + return m->verified_end(s, idx, s_config); } return true; } @@ -810,8 +810,8 @@ Module* ModuleManager::get_default_module(const char* s, SnortConfig* sc) if ( mod ) { - mod->begin(s, 0, sc); - mod->end(s, 0, nullptr); + mod->verified_begin(s, 0, sc); + mod->verified_end(s, 0, nullptr); } return mod; }