diff --git a/components/livestatus/attributefilter.cpp b/components/livestatus/attributefilter.cpp index 72aa8e2f0..bf693bcbd 100644 --- a/components/livestatus/attributefilter.cpp +++ b/components/livestatus/attributefilter.cpp @@ -60,10 +60,16 @@ bool AttributeFilter::Apply(const Table::Ptr& table, const Value& row) else return (static_cast(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(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(value) + "' " + (ret ? "matches" : "doesn't match") + "." ); diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index c925a0849..8aacbc00d 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -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)