Merge pull request #6104 from Icinga/fix/nullptr-deref

Fix nullptr dereferences
This commit is contained in:
Jean Flach 2018-02-21 13:56:09 +01:00 committed by GitHub
commit eda9bce8cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 103 additions and 47 deletions

View File

@ -30,6 +30,7 @@ static double ArrayLen()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->GetLength(); return self->GetLength();
} }
@ -37,6 +38,7 @@ static void ArraySet(int index, const Value& value)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
self->Set(index, value); self->Set(index, value);
} }
@ -44,6 +46,7 @@ static Value ArrayGet(int index)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->Get(index); return self->Get(index);
} }
@ -51,6 +54,7 @@ static void ArrayAdd(const Value& value)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
self->Add(value); self->Add(value);
} }
@ -58,6 +62,7 @@ static void ArrayRemove(int index)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
self->Remove(index); self->Remove(index);
} }
@ -65,6 +70,7 @@ static bool ArrayContains(const Value& value)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->Contains(value); return self->Contains(value);
} }
@ -72,6 +78,7 @@ static void ArrayClear()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
self->Clear(); self->Clear();
} }
@ -84,6 +91,7 @@ static Array::Ptr ArraySort(const std::vector<Value>& args)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
Array::Ptr arr = self->ShallowClone(); Array::Ptr arr = self->ShallowClone();
@ -107,6 +115,7 @@ static Array::Ptr ArrayShallowClone()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->ShallowClone(); return self->ShallowClone();
} }
@ -114,6 +123,7 @@ static Value ArrayJoin(const Value& separator)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
Value result; Value result;
bool first = true; bool first = true;
@ -136,6 +146,7 @@ static Array::Ptr ArrayReverse()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->Reverse(); return self->Reverse();
} }
@ -143,6 +154,7 @@ static Array::Ptr ArrayMap(const Function::Ptr& function)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
if (vframe->Sandboxed && !function->IsSideEffectFree()) if (vframe->Sandboxed && !function->IsSideEffectFree())
BOOST_THROW_EXCEPTION(ScriptError("Map function must be side-effect free.")); BOOST_THROW_EXCEPTION(ScriptError("Map function must be side-effect free."));
@ -161,6 +173,7 @@ static Value ArrayReduce(const Function::Ptr& function)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
if (vframe->Sandboxed && !function->IsSideEffectFree()) if (vframe->Sandboxed && !function->IsSideEffectFree())
BOOST_THROW_EXCEPTION(ScriptError("Reduce function must be side-effect free.")); BOOST_THROW_EXCEPTION(ScriptError("Reduce function must be side-effect free."));
@ -182,6 +195,7 @@ static Array::Ptr ArrayFilter(const Function::Ptr& function)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
if (vframe->Sandboxed && !function->IsSideEffectFree()) if (vframe->Sandboxed && !function->IsSideEffectFree())
BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free.")); BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free."));
@ -201,6 +215,7 @@ static bool ArrayAny(const Function::Ptr& function)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
if (vframe->Sandboxed && !function->IsSideEffectFree()) if (vframe->Sandboxed && !function->IsSideEffectFree())
BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free.")); BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free."));
@ -218,6 +233,7 @@ static bool ArrayAll(const Function::Ptr& function)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
if (vframe->Sandboxed && !function->IsSideEffectFree()) if (vframe->Sandboxed && !function->IsSideEffectFree())
BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free.")); BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free."));
@ -234,6 +250,7 @@ static Array::Ptr ArrayUnique()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self); Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
std::set<Value> result; std::set<Value> result;

View File

@ -29,6 +29,7 @@ static void ConfigObjectModifyAttribute(const String& attr, const Value& value)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
ConfigObject::Ptr self = vframe->Self; ConfigObject::Ptr self = vframe->Self;
REQUIRE_NOT_NULL(self);
return self->ModifyAttribute(attr, value); return self->ModifyAttribute(attr, value);
} }
@ -36,6 +37,7 @@ static void ConfigObjectRestoreAttribute(const String& attr)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
ConfigObject::Ptr self = vframe->Self; ConfigObject::Ptr self = vframe->Self;
REQUIRE_NOT_NULL(self);
return self->RestoreAttribute(attr); return self->RestoreAttribute(attr);
} }

View File

@ -29,6 +29,7 @@ static String DateTimeFormat(const String& format)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
DateTime::Ptr self = static_cast<DateTime::Ptr>(vframe->Self); DateTime::Ptr self = static_cast<DateTime::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->Format(format); return self->Format(format);
} }

View File

@ -29,6 +29,7 @@ static double DictionaryLen()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self); Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->GetLength(); return self->GetLength();
} }
@ -36,6 +37,7 @@ static void DictionarySet(const String& key, const Value& value)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self); Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
self->Set(key, value); self->Set(key, value);
} }
@ -43,6 +45,7 @@ static Value DictionaryGet(const String& key)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self); Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->Get(key); return self->Get(key);
} }
@ -50,6 +53,7 @@ static void DictionaryRemove(const String& key)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self); Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
self->Remove(key); self->Remove(key);
} }
@ -57,6 +61,7 @@ static bool DictionaryContains(const String& key)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self); Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->Contains(key); return self->Contains(key);
} }
@ -64,6 +69,7 @@ static Dictionary::Ptr DictionaryShallowClone()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self); Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->ShallowClone(); return self->ShallowClone();
} }
@ -71,6 +77,8 @@ static Array::Ptr DictionaryKeys()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self); Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
ArrayData keys; ArrayData keys;
ObjectLock olock(self); ObjectLock olock(self);
for (const Dictionary::Pair& kv : self) { for (const Dictionary::Pair& kv : self) {
@ -83,6 +91,8 @@ static Array::Ptr DictionaryValues()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self); Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
ArrayData values; ArrayData values;
ObjectLock olock(self); ObjectLock olock(self);
for (const Dictionary::Pair& kv : self) { for (const Dictionary::Pair& kv : self) {

View File

@ -32,6 +32,7 @@ static Value FunctionCall(const std::vector<Value>& args)
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Function::Ptr self = static_cast<Function::Ptr>(vframe->Self); Function::Ptr self = static_cast<Function::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
std::vector<Value> uargs(args.begin() + 1, args.end()); std::vector<Value> uargs(args.begin() + 1, args.end());
return self->InvokeThis(args[0], uargs); return self->InvokeThis(args[0], uargs);
@ -41,6 +42,7 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Function::Ptr self = static_cast<Function::Ptr>(vframe->Self); Function::Ptr self = static_cast<Function::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
std::vector<Value> uargs; std::vector<Value> uargs;

View File

@ -29,6 +29,7 @@ static String ObjectToString()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Object::Ptr self = static_cast<Object::Ptr>(vframe->Self); Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->ToString(); return self->ToString();
} }
@ -36,6 +37,7 @@ static void ObjectNotifyAttribute(const String& attribute)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Object::Ptr self = static_cast<Object::Ptr>(vframe->Self); Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
self->NotifyField(self->GetReflectionType()->GetFieldId(attribute)); self->NotifyField(self->GetReflectionType()->GetFieldId(attribute));
} }
@ -43,6 +45,7 @@ static Object::Ptr ObjectClone()
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Object::Ptr self = static_cast<Object::Ptr>(vframe->Self); Object::Ptr self = static_cast<Object::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
return self->Clone(); return self->Clone();
} }

View File

@ -290,3 +290,9 @@ void icinga::DefaultObjectFactoryCheckArgs(const std::vector<Value>& args)
if (!args.empty()) if (!args.empty())
BOOST_THROW_EXCEPTION(std::invalid_argument("Constructor does not take any arguments.")); BOOST_THROW_EXCEPTION(std::invalid_argument("Constructor does not take any arguments."));
} }
void icinga::RequireNotNullInternal(const intrusive_ptr<Object>& object, const char *description)
{
if (!object)
BOOST_THROW_EXCEPTION(std::invalid_argument("Pointer must not be null: " + String(description)));
}

View File

@ -57,6 +57,10 @@ extern Value Empty;
DECLARE_PTR_TYPEDEFS(klass); \ DECLARE_PTR_TYPEDEFS(klass); \
IMPL_TYPE_LOOKUP(); IMPL_TYPE_LOOKUP();
#define REQUIRE_NOT_NULL(ptr) RequireNotNullInternal(ptr, #ptr)
void RequireNotNullInternal(const intrusive_ptr<Object>& object, const char *description);
void DefaultObjectFactoryCheckArgs(const std::vector<Value>& args); void DefaultObjectFactoryCheckArgs(const std::vector<Value>& args);
template<typename T> template<typename T>

View File

@ -35,6 +35,7 @@ static void TypeRegisterAttributeHandler(const String& fieldName, const Function
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Type::Ptr self = static_cast<Type::Ptr>(vframe->Self); Type::Ptr self = static_cast<Type::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
int fid = self->GetFieldId(fieldName); int fid = self->GetFieldId(fieldName);
self->RegisterAttributeHandler(fid, std::bind(&InvokeAttributeHandlerHelper, callback, _1, _2)); self->RegisterAttributeHandler(fid, std::bind(&InvokeAttributeHandlerHelper, callback, _1, _2));

View File

@ -30,6 +30,7 @@ static void CheckableProcessCheckResult(const CheckResult::Ptr& cr)
{ {
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Checkable::Ptr self = vframe->Self; Checkable::Ptr self = vframe->Self;
REQUIRE_NOT_NULL(self);
self->ProcessCheckResult(cr); self->ProcessCheckResult(cr);
} }

View File

@ -114,9 +114,6 @@ Value ClusterEvents::CheckResultAPIHandler(const MessageOrigin::Ptr& origin, con
return Empty; return Empty;
} }
if (!params)
return Empty;
CheckResult::Ptr cr; CheckResult::Ptr cr;
Array::Ptr vperf; Array::Ptr vperf;
@ -220,9 +217,6 @@ Value ClusterEvents::NextCheckChangedAPIHandler(const MessageOrigin::Ptr& origin
return Empty; return Empty;
} }
if (!params)
return Empty;
Host::Ptr host = Host::GetByName(params->Get("host")); Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) if (!host)
@ -284,9 +278,6 @@ Value ClusterEvents::NextNotificationChangedAPIHandler(const MessageOrigin::Ptr&
return Empty; return Empty;
} }
if (!params)
return Empty;
Notification::Ptr notification = Notification::GetByName(params->Get("notification")); Notification::Ptr notification = Notification::GetByName(params->Get("notification"));
if (!notification) if (!notification)
@ -344,9 +335,6 @@ Value ClusterEvents::ForceNextCheckChangedAPIHandler(const MessageOrigin::Ptr& o
return Empty; return Empty;
} }
if (!params)
return Empty;
Host::Ptr host = Host::GetByName(params->Get("host")); Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) if (!host)
@ -409,9 +397,6 @@ Value ClusterEvents::ForceNextNotificationChangedAPIHandler(const MessageOrigin:
return Empty; return Empty;
} }
if (!params)
return Empty;
Host::Ptr host = Host::GetByName(params->Get("host")); Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) if (!host)
@ -480,9 +465,6 @@ Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& orig
return Empty; return Empty;
} }
if (!params)
return Empty;
Host::Ptr host = Host::GetByName(params->Get("host")); Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) if (!host)
@ -546,9 +528,6 @@ Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr&
return Empty; return Empty;
} }
if (!params)
return Empty;
Host::Ptr host = Host::GetByName(params->Get("host")); Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) if (!host)
@ -612,9 +591,6 @@ Value ClusterEvents::SendNotificationsAPIHandler(const MessageOrigin::Ptr& origi
return Empty; return Empty;
} }
if (!params)
return Empty;
Host::Ptr host = Host::GetByName(params->Get("host")); Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) if (!host)
@ -706,9 +682,6 @@ Value ClusterEvents::NotificationSentUserAPIHandler(const MessageOrigin::Ptr& or
return Empty; return Empty;
} }
if (!params)
return Empty;
Host::Ptr host = Host::GetByName(params->Get("host")); Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) if (!host)
@ -822,9 +795,6 @@ Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::P
return Empty; return Empty;
} }
if (!params)
return Empty;
Host::Ptr host = Host::GetByName(params->Get("host")); Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host) if (!host)

View File

@ -37,6 +37,9 @@ Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolv
const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros, const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
bool useResolvedMacros, int recursionLevel) bool useResolvedMacros, int recursionLevel)
{ {
if (useResolvedMacros)
REQUIRE_NOT_NULL(resolvedMacros);
Value result; Value result;
if (str.IsEmpty()) if (str.IsEmpty())
@ -436,6 +439,9 @@ Value MacroProcessor::ResolveArguments(const Value& command, const Dictionary::P
const MacroProcessor::ResolverList& resolvers, const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& resolvers, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel)
{ {
if (useResolvedMacros)
REQUIRE_NOT_NULL(resolvedMacros);
Value resolvedCommand; Value resolvedCommand;
if (!arguments || command.IsObjectType<Array>() || command.IsObjectType<Function>()) if (!arguments || command.IsObjectType<Array>() || command.IsObjectType<Function>())
resolvedCommand = MacroProcessor::ResolveMacros(command, resolvers, cr, nullptr, resolvedCommand = MacroProcessor::ResolveMacros(command, resolvers, cr, nullptr,

View File

@ -38,6 +38,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterCheck, &ClusterCheckTask::ScriptFunc
void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
REQUIRE_NOT_NULL(cr);
if (resolvedMacros && !useResolvedMacros) if (resolvedMacros && !useResolvedMacros)
return; return;

View File

@ -34,6 +34,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterZoneCheck, &ClusterZoneCheckTask::Sc
void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
REQUIRE_NOT_NULL(cr);
ApiListener::Ptr listener = ApiListener::GetInstance(); ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener) { if (!listener) {

View File

@ -36,6 +36,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, DummyCheck, &DummyCheckTask::ScriptFunc, "c
void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
REQUIRE_NOT_NULL(cr);
CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
Host::Ptr host; Host::Ptr host;

View File

@ -31,9 +31,12 @@ using namespace icinga;
REGISTER_SCRIPTFUNCTION_NS(Internal, ExceptionCheck, &ExceptionCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros"); REGISTER_SCRIPTFUNCTION_NS(Internal, ExceptionCheck, &ExceptionCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
void ExceptionCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, void ExceptionCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
REQUIRE_NOT_NULL(cr);
if (resolvedMacros && !useResolvedMacros) if (resolvedMacros && !useResolvedMacros)
return; return;

View File

@ -38,6 +38,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, IcingaCheck, &IcingaCheckTask::ScriptFunc,
void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
REQUIRE_NOT_NULL(cr);
CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
Host::Ptr host; Host::Ptr host;

View File

@ -32,9 +32,12 @@ using namespace icinga;
REGISTER_SCRIPTFUNCTION_NS(Internal, NullCheck, &NullCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros"); REGISTER_SCRIPTFUNCTION_NS(Internal, NullCheck, &NullCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, void NullCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
REQUIRE_NOT_NULL(cr);
if (resolvedMacros && !useResolvedMacros) if (resolvedMacros && !useResolvedMacros)
return; return;
@ -47,5 +50,5 @@ void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult:
})); }));
cr->SetState(ServiceOK); cr->SetState(ServiceOK);
service->ProcessCheckResult(cr); checkable->ProcessCheckResult(cr);
} }

View File

@ -25,5 +25,7 @@ using namespace icinga;
REGISTER_SCRIPTFUNCTION_NS(Internal, NullEvent, &NullEventTask::ScriptFunc, "checkable:resolvedMacros:useResolvedMacros"); REGISTER_SCRIPTFUNCTION_NS(Internal, NullEvent, &NullEventTask::ScriptFunc, "checkable:resolvedMacros:useResolvedMacros");
void NullEventTask::ScriptFunc(const Checkable::Ptr&, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) void NullEventTask::ScriptFunc(const Checkable::Ptr& checkable, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ } {
REQUIRE_NOT_NULL(checkable);
}

View File

@ -36,6 +36,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, PluginCheck, &PluginCheckTask::ScriptFunc,
void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
REQUIRE_NOT_NULL(cr);
CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
Host::Ptr host; Host::Ptr host;

View File

@ -36,6 +36,8 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, PluginEvent, &PluginEventTask::ScriptFunc,
void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
EventCommand::Ptr commandObj = checkable->GetEventCommand(); EventCommand::Ptr commandObj = checkable->GetEventCommand();
Host::Ptr host; Host::Ptr host;

View File

@ -39,6 +39,9 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros, const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros,
bool useResolvedMacros) bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(notification);
REQUIRE_NOT_NULL(user);
NotificationCommand::Ptr commandObj = notification->GetCommand(); NotificationCommand::Ptr commandObj = notification->GetCommand();
auto type = static_cast<NotificationType>(itype); auto type = static_cast<NotificationType>(itype);

View File

@ -31,9 +31,12 @@ using namespace icinga;
REGISTER_SCRIPTFUNCTION_NS(Internal, RandomCheck, &RandomCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros"); REGISTER_SCRIPTFUNCTION_NS(Internal, RandomCheck, &RandomCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, void RandomCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ {
REQUIRE_NOT_NULL(checkable);
REQUIRE_NOT_NULL(cr);
if (resolvedMacros && !useResolvedMacros) if (resolvedMacros && !useResolvedMacros)
return; return;
@ -58,5 +61,5 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul
cr->SetState(static_cast<ServiceState>(Utility::Random() % 4)); cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
service->ProcessCheckResult(cr); checkable->ProcessCheckResult(cr);
} }

View File

@ -25,14 +25,18 @@ using namespace icinga;
REGISTER_SCRIPTFUNCTION_NS(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate, "tp:begin:end"); REGISTER_SCRIPTFUNCTION_NS(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate, "tp:begin:end");
REGISTER_SCRIPTFUNCTION_NS(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate, "tp:begin:end"); REGISTER_SCRIPTFUNCTION_NS(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate, "tp:begin:end");
Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr&, double, double) Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double, double)
{ {
REQUIRE_NOT_NULL(tp);
Array::Ptr segments = new Array(); Array::Ptr segments = new Array();
return segments; return segments;
} }
Array::Ptr TimePeriodTask::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr&, double begin, double end) Array::Ptr TimePeriodTask::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end)
{ {
REQUIRE_NOT_NULL(tp);
ArrayData segments; ArrayData segments;
for (long t = begin / 60 - 1; t * 60 < end; t++) { for (long t = begin / 60 - 1; t * 60 < end; t++) {

View File

@ -41,7 +41,7 @@ void EventQueue::ProcessEvent(const Dictionary::Ptr& event)
frame.Sandboxed = true; frame.Sandboxed = true;
try { try {
if (!FilterUtility::EvaluateFilter(frame, &*m_Filter, event, "event")) if (!FilterUtility::EvaluateFilter(frame, m_Filter.get(), event, "event"))
return; return;
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
Log(LogWarning, "EventQueue") Log(LogWarning, "EventQueue")

View File

@ -40,9 +40,6 @@ REGISTER_APIFUNCTION(UpdateCertificate, pki, &UpdateCertificateHandler);
Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{ {
if (!params)
return Empty;
String certText = params->Get("cert_request"); String certText = params->Get("cert_request");
std::shared_ptr<X509> cert; std::shared_ptr<X509> cert;

View File

@ -225,7 +225,11 @@ void JsonRpcConnection::MessageHandler(const String& jsonString)
Log(LogNotice, "JsonRpcConnection") Log(LogNotice, "JsonRpcConnection")
<< "Call to non-existent function '" << method << "' from endpoint '" << m_Identity << "'."; << "Call to non-existent function '" << method << "' from endpoint '" << m_Identity << "'.";
} else { } else {
resultMessage->Set("result", afunc->Invoke(origin, message->Get("params"))); Dictionary::Ptr params = message->Get("params");
if (params)
resultMessage->Set("result", afunc->Invoke(origin, params));
else
resultMessage->Set("result", Empty);
} }
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
/* TODO: Add a user readable error message for the remote caller */ /* TODO: Add a user readable error message for the remote caller */
@ -287,9 +291,6 @@ void JsonRpcConnection::DataAvailableHandler()
Value SetLogPositionHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) Value SetLogPositionHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{ {
if (!params)
return Empty;
double log_position = params->Get("log_position"); double log_position = params->Get("log_position");
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();