]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Adding ModuleManager check for invalid tables and list
authorJosh <jrosenba@cisco.com>
Tue, 30 Sep 2014 14:52:33 +0000 (09:52 -0500)
committerJosh <jrosenba@cisco.com>
Tue, 30 Sep 2014 14:52:33 +0000 (09:52 -0500)
src/main/modules.cc
src/managers/module_manager.cc
src/parser/cmd_line.cc

index f2f1c89faf019675e15bc2a01836a65b29acd79d..048332f440e9f64a71ab070505f43a8bf7e93841 100644 (file)
@@ -1274,7 +1274,7 @@ bool ProcessModule::end(const char* fqn, int idx, SnortConfig* sc)
     if (!strcmp(fqn, "process.threads"))
     {
         if (cpu == -1)
-            ParseError("%s - cpu must be an integer in the range"
+            ParseError("%s - cpu(%d) must be an integer in the range"
                 " of 0 < cpu < max_cpus", fqn, cpu);
 
         else if ((source.empty()) && (thread == -1))
index e324ef8d23ad40028471282fba1d0adf61438df0..5260041b1d8f298f498aff356b0600400467af95 100644 (file)
@@ -224,16 +224,17 @@ static void dump_table(string& key, const char* pfx, const Parameter* p, bool li
 // set methods
 //-------------------------------------------------------------------------
 
-static const Parameter* get_params(string& sfx, const Parameter* p)
+static const Parameter* get_params(const string& sfx, const Parameter* p)
 {
     size_t pos = sfx.find_first_of('.');
+    std::string new_fqn;
 
     if ( pos == string::npos )
-        return p;
-
-    sfx.erase(0, pos+1);
-    string name = sfx.substr(0, sfx.find_first_of('.'));
+        new_fqn = sfx;
+    else
+        new_fqn = sfx.substr(pos + 1);
 
+    string name = new_fqn.substr(0, new_fqn.find_first_of('.'));
     while ( p->name && name != p->name )
         ++p;
 
@@ -244,8 +245,11 @@ static const Parameter* get_params(string& sfx, const Parameter* p)
          p->type != Parameter::PT_LIST )
         return p;
 
+    if (new_fqn.find_first_of('.') == std::string::npos)
+        return p;
+
     p = (const Parameter*)p->range;
-    return get_params(sfx,  p);
+    return get_params(new_fqn, p);
 }
 
 // FIXIT-M vars may have been defined on command line
@@ -360,6 +364,23 @@ SO_PUBLIC bool open_table(const char* s, int idx)
 
     Module* m = h->mod;
 
+    if (strcmp(m->get_name(), s))
+    {
+        std::string fqn = s;
+        const Parameter* const p = get_params(fqn, m->get_parameters());
+
+        if ( !p )
+        {
+            ParseError("can't find %s\n", s);
+            return false;
+        }
+        else if ((idx > 0) && (p->type == Parameter::PT_TABLE))
+        {
+            ParseError("%s is a table. All elements must be name\n", s);
+            return false;
+        }
+    }
+
     if ( s_current != key )
     {
         LogMessage("\t %s\n", key.c_str());
index 4b2975c4f07cf58226924098b09bc56a00a86f0c..6b851548e8e93cb82506a266604a5794712c1429 100644 (file)
@@ -151,13 +151,13 @@ SnortConfig* parse_cmd_line(int argc, char* argv[])
 
     // get special options first
     while ( al.get_arg(key, val) )
-        set(key, val, sc, false);
+        ::set(key, val, sc, false);
 
     // now get the rest
     al.reset();
 
     while ( al.get_arg(key, val) )
-        set(key, val, sc, true);
+        ::set(key, val, sc, true);
 
     check_flags(sc);