summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2009-07-30 09:47:03 +0000
committerdeva <deva>2009-07-30 09:47:03 +0000
commit7648d777302595d819e2a34e41bbda157392667b (patch)
treef97a75e7f87f8156016a043bfd22f7508d3f48af
parent706e18fae5713e070d6379f1ec9da1757b338f4e (diff)
Make sure we don't hang in an infinite loop when encountering malformed macro/template files.
-rw-r--r--server/src/macroheaderparser.cc6
-rw-r--r--server/src/macrolist.cc10
-rw-r--r--server/src/macrotool_dump.cc70
-rw-r--r--server/src/templateheaderparser.cc6
-rw-r--r--server/src/templatelist.cc11
5 files changed, 65 insertions, 38 deletions
diff --git a/server/src/macroheaderparser.cc b/server/src/macroheaderparser.cc
index d6ba0bb..def80c3 100644
--- a/server/src/macroheaderparser.cc
+++ b/server/src/macroheaderparser.cc
@@ -94,11 +94,13 @@ MacroHeaderParser::~MacroHeaderParser()
void MacroHeaderParser::startTag(std::string name, std::map< std::string, std::string> attributes)
{
- // Create macro and enable parsing of queries, maps and widgets
+ if(m) return;
+
if(name == "macro") {
- assert(!m); // A Macro has already been allocated, cannot create macro!
m = new Macro();
m->attributes = attributes;
+ } else {
+ throw Exception("Missing root tag 'macro' - found '" + name + "'");
}
}
diff --git a/server/src/macrolist.cc b/server/src/macrolist.cc
index 0e86a47..b67f239 100644
--- a/server/src/macrolist.cc
+++ b/server/src/macrolist.cc
@@ -63,9 +63,13 @@ MacroList::MacroList(std::string macropath)
std::vector<std::string>::iterator i = macros.begin();
while(i != macros.end()) {
MacroHeaderParser parser(macropath + "/" + *i);
- parser.parse();
- Macro *macro = parser.getMacro();
- (*this)[macro->attributes["name"]][VersionStr(macro->attributes["version"])] = *i;
+ try {
+ parser.parse();
+ Macro *macro = parser.getMacro();
+ (*this)[macro->attributes["name"]][VersionStr(macro->attributes["version"])] = *i;
+ } catch(Exception &e) {
+ PRACRO_WARN(macrolist, "Skipping %s: %s\n", i->c_str(), e.what());
+ }
i++;
}
diff --git a/server/src/macrotool_dump.cc b/server/src/macrotool_dump.cc
index d108e54..f570a15 100644
--- a/server/src/macrotool_dump.cc
+++ b/server/src/macrotool_dump.cc
@@ -42,6 +42,8 @@
#include "configuration.h"
+#include "exception.h"
+
struct _macro {
std::string name;
std::string title;
@@ -74,14 +76,18 @@ static std::map<std::string, struct _macro> macroList()
//std::string name = mfs->substr(0, mfs->length() - 4);
MacroParser parser(Conf::xml_basedir + "/macros/" + *mfs);
- parser.parse();
- Macro *macro = parser.getMacro();
-
- std::string key = macro->attributes["name"];// + "-" + macro->attributes["version"];
- macros[key].name = macro->attributes["name"];
- macros[key].file = *mfs;
- macros[key].title = macro->widgets.attributes["caption"];
- macros[key].version = macro->attributes["version"];
+ try {
+ parser.parse();
+ Macro *macro = parser.getMacro();
+
+ std::string key = macro->attributes["name"];// + "-" + macro->attributes["version"];
+ macros[key].name = macro->attributes["name"];
+ macros[key].file = *mfs;
+ macros[key].title = macro->widgets.attributes["caption"];
+ macros[key].version = macro->attributes["version"];
+ } catch( Exception &e ) {
+ printf("Skipping: %s: %s\n", mfs->c_str(), e.what());
+ }
mfs++;
}
@@ -91,14 +97,19 @@ static std::map<std::string, struct _macro> macroList()
while(tfs != templatefiles.end()) {
std::string templ = tfs->substr(0, tfs->length() - 4);
TemplateParser parser(Conf::xml_basedir + "/templates/" + *tfs);
- parser.parse();
- Template *t = parser.getTemplate();
- std::vector<Macro>::iterator ms = t->macros.begin();
- while(ms != t->macros.end()) {
- if(ms->attributes.find("header") == ms->attributes.end())
- macros[ms->attributes["name"]].templates.insert(templ);
- ms++;
+ try {
+ parser.parse();
+ Template *t = parser.getTemplate();
+ std::vector<Macro>::iterator ms = t->macros.begin();
+ while(ms != t->macros.end()) {
+ if(ms->attributes.find("header") == ms->attributes.end())
+ macros[ms->attributes["name"]].templates.insert(templ);
+ ms++;
+ }
+ } catch( Exception &e ) {
+ printf("Skipping: %s: %s\n", tfs->c_str(), e.what());
}
+
tfs++;
}
@@ -155,23 +166,26 @@ static std::map<std::string, struct _template> templateList()
std::vector<std::string>::iterator tfs = templatefiles.begin();
while(tfs != templatefiles.end()) {
TemplateParser parser(Conf::xml_basedir + "/templates/" + *tfs);
- parser.parse();
- Template *t = parser.getTemplate();
+ try {
+ parser.parse();
+ Template *t = parser.getTemplate();
- std::string key = t->attributes["name"];
+ std::string key = t->attributes["name"];
- templates[key].file = *tfs;
- templates[key].name = t->attributes["name"];
- templates[key].title = t->attributes["title"];
- templates[key].version = t->attributes["version"];
+ templates[key].file = *tfs;
+ templates[key].name = t->attributes["name"];
+ templates[key].title = t->attributes["title"];
+ templates[key].version = t->attributes["version"];
- std::vector<Macro>::iterator ms = t->macros.begin();
- while(ms != t->macros.end()) {
- if(ms->attributes.find("header") == ms->attributes.end())
- templates[key].macros.push_back(ms->attributes["name"]);
- ms++;
+ std::vector<Macro>::iterator ms = t->macros.begin();
+ while(ms != t->macros.end()) {
+ if(ms->attributes.find("header") == ms->attributes.end())
+ templates[key].macros.push_back(ms->attributes["name"]);
+ ms++;
+ }
+ } catch( Exception &e ) {
+ printf("Skipping: %s: %s\n", tfs->c_str(), e.what());
}
-
tfs++;
}
diff --git a/server/src/templateheaderparser.cc b/server/src/templateheaderparser.cc
index 8698e05..0b274ee 100644
--- a/server/src/templateheaderparser.cc
+++ b/server/src/templateheaderparser.cc
@@ -94,11 +94,13 @@ TemplateHeaderParser::~TemplateHeaderParser()
void TemplateHeaderParser::startTag(std::string name, std::map< std::string, std::string> attributes)
{
- // Create template and enable parsing of queries, maps and widgets
+ if(t) return;
+
if(name == "template") {
- assert(!t); // A Template has already been allocated, cannot create template!
t = new Template();
t->attributes = attributes;
+ } else {
+ throw Exception("Missing root tag 'template' - found '" + name + "'");
}
}
diff --git a/server/src/templatelist.cc b/server/src/templatelist.cc
index 2e6f176..cdf2b4b 100644
--- a/server/src/templatelist.cc
+++ b/server/src/templatelist.cc
@@ -63,9 +63,14 @@ TemplateList::TemplateList(std::string templatepath)
std::vector<std::string>::iterator i = templates.begin();
while(i != templates.end()) {
TemplateHeaderParser parser(templatepath + "/" + *i);
- parser.parse();
- Template *templ = parser.getTemplate();
- (*this)[templ->attributes["name"]][VersionStr(templ->attributes["version"])] = *i;
+ try {
+ parser.parse();
+ Template *templ = parser.getTemplate();
+ (*this)[templ->attributes["name"]][VersionStr(templ->attributes["version"])] = *i;
+ } catch(Exception &e) {
+ PRACRO_WARN(templatelist, "Skipping %s: %s\n", i->c_str(), e.what());
+ }
+
i++;
}