]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Fixed asciidoc bug. Sanitize all markup strings before output
authorJosh <jrosenba@cisco.com>
Mon, 22 Sep 2014 21:22:37 +0000 (17:22 -0400)
committerJosh <jrosenba@cisco.com>
Mon, 22 Sep 2014 21:22:45 +0000 (17:22 -0400)
src/helpers/markup.cc
src/helpers/markup.h
src/main/help.cc
src/managers/module_manager.cc
src/managers/plugin_manager.cc

index b75462417102c93927a7dab121cfd54f461febe3..5cdf04654979470705fdcae17ea1bb2a31c0fc05 100644 (file)
@@ -48,3 +48,26 @@ const string& Markup::emphasis(const string& s)
     return m;
 }
 
+const std::string& Markup::sanitize(const char* const c)
+{ return sanitize(std::string(c)); }
+
+const std::string& Markup::sanitize(const std::string& s)
+{
+    const char* const asciidoc_chars = "~*<>^'";
+    static std::string m;
+    m.clear();
+    m += s;
+
+    if (enabled)
+    {
+        for (std::size_t found = m.find_first_of(asciidoc_chars, 0);
+             found != std::string::npos;
+             found = m.find_first_of(asciidoc_chars, found))
+        {
+            m.insert(found, "\\");
+            found +=2;
+        }
+    }
+
+    return m;
+}
index ea427e469e4db02d7851d712f0b1f134f21596b9..92d2f80a1fc04eca9e347e244d66d53e25cb41a5 100644 (file)
@@ -34,6 +34,8 @@ public:
     static const char* emphasis_on();
     static const char* emphasis_off();
     static const std::string& emphasis(const std::string&);
+    static const std::string& sanitize(const char* const);
+    static const std::string& sanitize(const std::string&);
 
 private:
     static bool enabled;
index c54883e0417dcdd520995e86caad069fb0256a7b..9f3ea526afca8f2b7669833aab06256e13104b37 100644 (file)
@@ -104,10 +104,10 @@ void help_args(const char* pfx)
 
             //const char* prefix = strlen(p->name) > 1 ? "--" : "-";
             //cout << prefix << p->name;
-            cout << p->name;
+            cout << Markup::sanitize(p->name);
             cout << Markup::emphasis_off();
 
-            cout << " " << p->help;
+            cout << " " << Markup::sanitize(p->help);
             cout << endl;
         }
         ++p;
index 402f1c436cb33adadae9f5ec9578ad4334db2a4c..deab6b13b66465edd4e639d7bd286692b9dc4562 100644 (file)
@@ -181,30 +181,30 @@ static void dump_field(string& key, const char* pfx, const Parameter* p, bool li
     {
 #if 1
         cout << Markup::item();
-        cout << p->get_type();
-        cout << " " << Markup::emphasis(key);
+        cout << Markup::sanitize(p->get_type());
+        cout << " " << Markup::emphasis(Markup::sanitize(key));
 
         if ( p->deflt )
-            cout << " = " << (char*)p->deflt;
+            cout << " = " << Markup::sanitize((char*)p->deflt);
 
         cout << ": " << p->help;
 
         if ( p->range )
-            cout << " { " << (char*)p->range << " }";
+            cout << " { " << Markup::sanitize((char*)p->range) << " }";
 #else
         cout << Markup::item();
         cout << p->get_type();
-        cout << "\t" << Markup::emphasis(key);
+        cout << "\t" << Markup::emphasis(Markup::sanitize(key));
 
         if ( p->deflt )
-            cout << "\t" << (char*)p->deflt;
+            cout << "\t" << Markup::sanitize((char*)p->deflt);
         else
             cout << "\t";
 
         cout << "\t" << p->help;
 
         if ( p->range )
-            cout << "\t" << (const char*)p->range;
+            cout << "\t" << Markup::sanitize((char*)p->range);
         else
             cout << "\t";
 
@@ -522,10 +522,10 @@ void ModuleManager::show_module(const char* name)
         if ( strcmp(m->get_name(), name) )
             continue;
 
-        cout << endl << Markup::head() << name << endl << endl;
+        cout << endl << Markup::head() << Markup::sanitize(name) << endl << endl;
 
         if ( const char* h = m->get_help() )
-            cout << "What: " << h << endl;
+            cout << "What: " << Markup::sanitize(h) << endl;
 
         cout << "Type: "  << mod_type(p->api) << endl;
 
@@ -614,10 +614,10 @@ void ModuleManager::show_commands(const char* pfx)
         {
             cout << Markup::item();
             cout << Markup::emphasis_on();
-            cout << p->mod->get_name();
-            cout << "." << c->name;
+            cout << Markup::sanitize(p->mod->get_name());
+            cout << "." << Markup::sanitize(c->name);
             cout << Markup::emphasis_off();
-            cout << "(): " << c->help;
+            cout << "(): " << Markup::sanitize(c->help);
             cout << endl;
             c++;
         }
@@ -645,7 +645,7 @@ void ModuleManager::show_gids(const char* pfx)
             cout << Markup::emphasis_on();
             cout << gid;
             cout << Markup::emphasis_off();
-            cout << ": " << m->get_name();
+            cout << ": " << Markup::sanitize(m->get_name());
             cout << endl;
         }
     }    
@@ -673,7 +673,7 @@ void ModuleManager::show_pegs(const char* pfx)
         {
             cout << Markup::item();
             cout << Markup::emphasis_on();
-            cout << *pegs;
+            cout << Markup::sanitize(*pegs);
             cout << Markup::emphasis_off();
             cout << endl;
             ++pegs;
@@ -705,7 +705,7 @@ void ModuleManager::show_rules(const char* pfx)
             cout << Markup::emphasis_on();
             cout << gid << ":" << r->sid;
             cout << Markup::emphasis_off();
-            cout << " " << r->msg;
+            cout << " " << Markup::sanitize(r->msg);
             cout << endl;
             r++;
         }
index 663b655af009231d3d8ad7fcc443740d65a7dfef..2b298da5fa2ab564ab274e7ec20bece19b6acb91 100644 (file)
@@ -360,7 +360,7 @@ void PluginManager::list_plugins()
     {
         Plugin& p = it->second;
         cout << Markup::item();
-        cout << p.key;
+        cout << Markup::sanitize(p.key);
         if ( p.api->mod_ctor )
             cout << " (module)";
         cout << endl;