]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #783 in SNORT/snort3 from lua_lists to master
authorShawn Turner (shaturne) <shaturne@cisco.com>
Fri, 20 Jan 2017 18:14:53 +0000 (13:14 -0500)
committerShawn Turner (shaturne) <shaturne@cisco.com>
Fri, 20 Jan 2017 18:14:53 +0000 (13:14 -0500)
Squashed commit of the following:

commit 45d53c105a64464e1eb44335252985b1b430d4e2
Author: Carter Waxman <cwaxman@cisco.com>
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

src/framework/module.cc
src/framework/module.h
src/managers/module_manager.cc

index cf237e69c602c00b7b5e2dc59b792e3c439ecc26..134ae02f57e196fd3210789d6e75000a173ecf02 100644 (file)
@@ -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" },
index 341cd0eeefbd30d7d692e6c78f50b1111820f743..07c32ac22123c40418c3481b29589d9f5dd6f955 100644 (file)
@@ -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;
 };
index 7b604e36aa3a28e157d7bc8887ec6d06cede1f92..bed9f93802d56de746898f8c58b73faec4ba716b 100644 (file)
@@ -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;
 }