From: Josh Date: Mon, 22 Sep 2014 21:22:37 +0000 (-0400) Subject: Fixed asciidoc bug. Sanitize all markup strings before output X-Git-Tag: 3.0.0-233~1404^2~10^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc6d04fc5a9241dfbf1ac6e1c713667e189aef80;p=thirdparty%2Fsnort3.git Fixed asciidoc bug. Sanitize all markup strings before output --- diff --git a/src/helpers/markup.cc b/src/helpers/markup.cc index b75462417..5cdf04654 100644 --- a/src/helpers/markup.cc +++ b/src/helpers/markup.cc @@ -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; +} diff --git a/src/helpers/markup.h b/src/helpers/markup.h index ea427e469..92d2f80a1 100644 --- a/src/helpers/markup.h +++ b/src/helpers/markup.h @@ -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; diff --git a/src/main/help.cc b/src/main/help.cc index c54883e04..9f3ea526a 100644 --- a/src/main/help.cc +++ b/src/main/help.cc @@ -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; diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 402f1c436..deab6b13b 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -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++; } diff --git a/src/managers/plugin_manager.cc b/src/managers/plugin_manager.cc index 663b655af..2b298da5f 100644 --- a/src/managers/plugin_manager.cc +++ b/src/managers/plugin_manager.cc @@ -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;