Error Messages: Catch boost::regex exceptions.

Refs #6070
This commit is contained in:
Michael Friedrich 2014-06-05 16:13:28 +02:00
parent a416987031
commit 6a080edf80
2 changed files with 30 additions and 11 deletions

View File

@ -60,10 +60,16 @@ bool AttributeFilter::Apply(const Table::Ptr& table, const Value& row)
else
return (static_cast<String>(value) == m_Operand);
} else if (m_Operator == "~") {
boost::regex expr(m_Operand.GetData());
String operand = value;
boost::smatch what;
bool ret = boost::regex_search(operand.GetData(), what, expr);
bool ret;
try {
boost::regex expr(m_Operand.GetData());
String operand = value;
boost::smatch what;
ret = boost::regex_search(operand.GetData(), what, expr);
} catch (boost::exception&) {
Log(LogWarning, "AttributeFilter", "Regex '" + m_Operand + " " + m_Operator + " " + Convert::ToString(value) + "' error.");
ret = false;
}
//Log(LogDebug, "LivestatusListener/AttributeFilter", "Attribute filter '" + m_Operand + " " + m_Operator + " " +
// static_cast<String>(value) + "' " + (ret ? "matches" : "doesn't match") + "." );
@ -72,10 +78,16 @@ bool AttributeFilter::Apply(const Table::Ptr& table, const Value& row)
} else if (m_Operator == "=~") {
return string_iless()(value, m_Operand);
} else if (m_Operator == "~~") {
boost::regex expr(m_Operand.GetData(), boost::regex::icase);
String operand = value;
boost::smatch what;
bool ret = boost::regex_search(operand.GetData(), what, expr);
bool ret;
try {
boost::regex expr(m_Operand.GetData(), boost::regex::icase);
String operand = value;
boost::smatch what;
ret = boost::regex_search(operand.GetData(), what, expr);
} catch (boost::exception&) {
Log(LogWarning, "AttributeFilter", "Regex '" + m_Operand + " " + m_Operator + " " + Convert::ToString(value) + "' error.");
ret = false;
}
//Log(LogDebug, "LivestatusListener/AttributeFilter", "Attribute filter '" + m_Operand + " " + m_Operator + " " +
// static_cast<String>(value) + "' " + (ret ? "matches" : "doesn't match") + "." );

View File

@ -43,9 +43,16 @@ REGISTER_SCRIPTFUNCTION(exit, &ScriptUtils::Exit);
bool ScriptUtils::Regex(const String& pattern, const String& text)
{
boost::regex expr(pattern.GetData());
boost::smatch what;
return boost::regex_search(text.GetData(), what, expr);
bool res = false;
try {
boost::regex expr(pattern.GetData());
boost::smatch what;
res = boost::regex_search(text.GetData(), what, expr);
} catch (boost::exception&) {
res = false; /* exception means something went terribly wrong */
}
return res;
}
int ScriptUtils::Len(const Value& value)