diff --git a/lib/base/array-script.cpp b/lib/base/array-script.cpp index 3a59b7fb8..3f83dd934 100644 --- a/lib/base/array-script.cpp +++ b/lib/base/array-script.cpp @@ -30,6 +30,7 @@ static double ArrayLen() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->GetLength(); } @@ -37,6 +38,7 @@ static void ArraySet(int index, const Value& value) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); self->Set(index, value); } @@ -44,6 +46,7 @@ static Value ArrayGet(int index) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->Get(index); } @@ -51,6 +54,7 @@ static void ArrayAdd(const Value& value) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); self->Add(value); } @@ -58,6 +62,7 @@ static void ArrayRemove(int index) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); self->Remove(index); } @@ -65,6 +70,7 @@ static bool ArrayContains(const Value& value) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->Contains(value); } @@ -72,6 +78,7 @@ static void ArrayClear() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); self->Clear(); } @@ -84,6 +91,7 @@ static Array::Ptr ArraySort(const std::vector& args) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); Array::Ptr arr = self->ShallowClone(); @@ -107,6 +115,7 @@ static Array::Ptr ArrayShallowClone() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->ShallowClone(); } @@ -114,6 +123,7 @@ static Value ArrayJoin(const Value& separator) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); Value result; bool first = true; @@ -136,6 +146,7 @@ static Array::Ptr ArrayReverse() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->Reverse(); } @@ -143,6 +154,7 @@ static Array::Ptr ArrayMap(const Function::Ptr& function) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); if (vframe->Sandboxed && !function->IsSideEffectFree()) 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(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); if (vframe->Sandboxed && !function->IsSideEffectFree()) 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(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); if (vframe->Sandboxed && !function->IsSideEffectFree()) 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(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); if (vframe->Sandboxed && !function->IsSideEffectFree()) 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(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); if (vframe->Sandboxed && !function->IsSideEffectFree()) BOOST_THROW_EXCEPTION(ScriptError("Filter function must be side-effect free.")); @@ -234,6 +250,7 @@ static Array::Ptr ArrayUnique() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Array::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); std::set result; diff --git a/lib/base/configobject-script.cpp b/lib/base/configobject-script.cpp index d2cdba45b..9f615eca7 100644 --- a/lib/base/configobject-script.cpp +++ b/lib/base/configobject-script.cpp @@ -29,6 +29,7 @@ static void ConfigObjectModifyAttribute(const String& attr, const Value& value) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ConfigObject::Ptr self = vframe->Self; + REQUIRE_NOT_NULL(self); return self->ModifyAttribute(attr, value); } @@ -36,6 +37,7 @@ static void ConfigObjectRestoreAttribute(const String& attr) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); ConfigObject::Ptr self = vframe->Self; + REQUIRE_NOT_NULL(self); return self->RestoreAttribute(attr); } diff --git a/lib/base/datetime-script.cpp b/lib/base/datetime-script.cpp index 4a16a0aa2..c26177af1 100644 --- a/lib/base/datetime-script.cpp +++ b/lib/base/datetime-script.cpp @@ -29,6 +29,7 @@ static String DateTimeFormat(const String& format) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); DateTime::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->Format(format); } diff --git a/lib/base/dictionary-script.cpp b/lib/base/dictionary-script.cpp index 547f814b1..d188119e5 100644 --- a/lib/base/dictionary-script.cpp +++ b/lib/base/dictionary-script.cpp @@ -29,6 +29,7 @@ static double DictionaryLen() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Dictionary::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->GetLength(); } @@ -36,6 +37,7 @@ static void DictionarySet(const String& key, const Value& value) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Dictionary::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); self->Set(key, value); } @@ -43,6 +45,7 @@ static Value DictionaryGet(const String& key) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Dictionary::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->Get(key); } @@ -50,6 +53,7 @@ static void DictionaryRemove(const String& key) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Dictionary::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); self->Remove(key); } @@ -57,6 +61,7 @@ static bool DictionaryContains(const String& key) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Dictionary::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->Contains(key); } @@ -64,6 +69,7 @@ static Dictionary::Ptr DictionaryShallowClone() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Dictionary::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->ShallowClone(); } @@ -71,6 +77,8 @@ static Array::Ptr DictionaryKeys() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Dictionary::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); + ArrayData keys; ObjectLock olock(self); for (const Dictionary::Pair& kv : self) { @@ -83,6 +91,8 @@ static Array::Ptr DictionaryValues() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Dictionary::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); + ArrayData values; ObjectLock olock(self); for (const Dictionary::Pair& kv : self) { diff --git a/lib/base/function-script.cpp b/lib/base/function-script.cpp index 757eb4e2d..8a96b26f2 100644 --- a/lib/base/function-script.cpp +++ b/lib/base/function-script.cpp @@ -32,6 +32,7 @@ static Value FunctionCall(const std::vector& args) ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Function::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); std::vector uargs(args.begin() + 1, args.end()); return self->InvokeThis(args[0], uargs); @@ -41,6 +42,7 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Function::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); std::vector uargs; diff --git a/lib/base/object-script.cpp b/lib/base/object-script.cpp index 8c42314d6..6db6374e8 100644 --- a/lib/base/object-script.cpp +++ b/lib/base/object-script.cpp @@ -29,6 +29,7 @@ static String ObjectToString() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Object::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->ToString(); } @@ -36,6 +37,7 @@ static void ObjectNotifyAttribute(const String& attribute) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Object::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); self->NotifyField(self->GetReflectionType()->GetFieldId(attribute)); } @@ -43,6 +45,7 @@ static Object::Ptr ObjectClone() { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Object::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); return self->Clone(); } diff --git a/lib/base/object.cpp b/lib/base/object.cpp index e81422879..b1fff79d2 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -290,3 +290,9 @@ void icinga::DefaultObjectFactoryCheckArgs(const std::vector& args) if (!args.empty()) BOOST_THROW_EXCEPTION(std::invalid_argument("Constructor does not take any arguments.")); } + +void icinga::RequireNotNullInternal(const intrusive_ptr& object, const char *description) +{ + if (!object) + BOOST_THROW_EXCEPTION(std::invalid_argument("Pointer must not be null: " + String(description))); +} diff --git a/lib/base/object.hpp b/lib/base/object.hpp index bd1128f57..a29e4f73b 100644 --- a/lib/base/object.hpp +++ b/lib/base/object.hpp @@ -57,6 +57,10 @@ extern Value Empty; DECLARE_PTR_TYPEDEFS(klass); \ IMPL_TYPE_LOOKUP(); +#define REQUIRE_NOT_NULL(ptr) RequireNotNullInternal(ptr, #ptr) + +void RequireNotNullInternal(const intrusive_ptr& object, const char *description); + void DefaultObjectFactoryCheckArgs(const std::vector& args); template diff --git a/lib/base/typetype-script.cpp b/lib/base/typetype-script.cpp index 0a6cfbc1d..88ebe3c92 100644 --- a/lib/base/typetype-script.cpp +++ b/lib/base/typetype-script.cpp @@ -35,6 +35,7 @@ static void TypeRegisterAttributeHandler(const String& fieldName, const Function { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Type::Ptr self = static_cast(vframe->Self); + REQUIRE_NOT_NULL(self); int fid = self->GetFieldId(fieldName); self->RegisterAttributeHandler(fid, std::bind(&InvokeAttributeHandlerHelper, callback, _1, _2)); diff --git a/lib/icinga/checkable-script.cpp b/lib/icinga/checkable-script.cpp index 5d969e3f4..532fb58dd 100644 --- a/lib/icinga/checkable-script.cpp +++ b/lib/icinga/checkable-script.cpp @@ -30,6 +30,7 @@ static void CheckableProcessCheckResult(const CheckResult::Ptr& cr) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); Checkable::Ptr self = vframe->Self; + REQUIRE_NOT_NULL(self); self->ProcessCheckResult(cr); } diff --git a/lib/icinga/clusterevents.cpp b/lib/icinga/clusterevents.cpp index 9ae894db1..e892caabf 100644 --- a/lib/icinga/clusterevents.cpp +++ b/lib/icinga/clusterevents.cpp @@ -114,9 +114,6 @@ Value ClusterEvents::CheckResultAPIHandler(const MessageOrigin::Ptr& origin, con return Empty; } - if (!params) - return Empty; - CheckResult::Ptr cr; Array::Ptr vperf; @@ -220,9 +217,6 @@ Value ClusterEvents::NextCheckChangedAPIHandler(const MessageOrigin::Ptr& origin return Empty; } - if (!params) - return Empty; - Host::Ptr host = Host::GetByName(params->Get("host")); if (!host) @@ -284,9 +278,6 @@ Value ClusterEvents::NextNotificationChangedAPIHandler(const MessageOrigin::Ptr& return Empty; } - if (!params) - return Empty; - Notification::Ptr notification = Notification::GetByName(params->Get("notification")); if (!notification) @@ -344,9 +335,6 @@ Value ClusterEvents::ForceNextCheckChangedAPIHandler(const MessageOrigin::Ptr& o return Empty; } - if (!params) - return Empty; - Host::Ptr host = Host::GetByName(params->Get("host")); if (!host) @@ -409,9 +397,6 @@ Value ClusterEvents::ForceNextNotificationChangedAPIHandler(const MessageOrigin: return Empty; } - if (!params) - return Empty; - Host::Ptr host = Host::GetByName(params->Get("host")); if (!host) @@ -480,9 +465,6 @@ Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& orig return Empty; } - if (!params) - return Empty; - Host::Ptr host = Host::GetByName(params->Get("host")); if (!host) @@ -546,9 +528,6 @@ Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& return Empty; } - if (!params) - return Empty; - Host::Ptr host = Host::GetByName(params->Get("host")); if (!host) @@ -612,9 +591,6 @@ Value ClusterEvents::SendNotificationsAPIHandler(const MessageOrigin::Ptr& origi return Empty; } - if (!params) - return Empty; - Host::Ptr host = Host::GetByName(params->Get("host")); if (!host) @@ -706,9 +682,6 @@ Value ClusterEvents::NotificationSentUserAPIHandler(const MessageOrigin::Ptr& or return Empty; } - if (!params) - return Empty; - Host::Ptr host = Host::GetByName(params->Get("host")); if (!host) @@ -822,9 +795,6 @@ Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::P return Empty; } - if (!params) - return Empty; - Host::Ptr host = Host::GetByName(params->Get("host")); if (!host) diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index d0c4fde8c..d99f7649d 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -37,6 +37,9 @@ Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolv const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel) { + if (useResolvedMacros) + REQUIRE_NOT_NULL(resolvedMacros); + Value result; 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 Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int recursionLevel) { + if (useResolvedMacros) + REQUIRE_NOT_NULL(resolvedMacros); + Value resolvedCommand; if (!arguments || command.IsObjectType() || command.IsObjectType()) resolvedCommand = MacroProcessor::ResolveMacros(command, resolvers, cr, nullptr, diff --git a/lib/methods/clusterchecktask.cpp b/lib/methods/clusterchecktask.cpp index 85604dd62..7473eb1ad 100644 --- a/lib/methods/clusterchecktask.cpp +++ b/lib/methods/clusterchecktask.cpp @@ -38,6 +38,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterCheck, &ClusterCheckTask::ScriptFunc void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + REQUIRE_NOT_NULL(checkable); + REQUIRE_NOT_NULL(cr); + if (resolvedMacros && !useResolvedMacros) return; diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 4bb114690..76a6fb2b2 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -34,6 +34,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterZoneCheck, &ClusterZoneCheckTask::Sc void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + REQUIRE_NOT_NULL(checkable); + REQUIRE_NOT_NULL(cr); + ApiListener::Ptr listener = ApiListener::GetInstance(); if (!listener) { diff --git a/lib/methods/dummychecktask.cpp b/lib/methods/dummychecktask.cpp index 10378e64a..516cc23ea 100644 --- a/lib/methods/dummychecktask.cpp +++ b/lib/methods/dummychecktask.cpp @@ -36,6 +36,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, DummyCheck, &DummyCheckTask::ScriptFunc, "c void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + REQUIRE_NOT_NULL(checkable); + REQUIRE_NOT_NULL(cr); + CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); Host::Ptr host; diff --git a/lib/methods/exceptionchecktask.cpp b/lib/methods/exceptionchecktask.cpp index a808036de..cb5ce76df 100644 --- a/lib/methods/exceptionchecktask.cpp +++ b/lib/methods/exceptionchecktask.cpp @@ -31,9 +31,12 @@ using namespace icinga; 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) { + REQUIRE_NOT_NULL(checkable); + REQUIRE_NOT_NULL(cr); + if (resolvedMacros && !useResolvedMacros) return; diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 16f58e71d..5eca99b3f 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -38,6 +38,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, IcingaCheck, &IcingaCheckTask::ScriptFunc, void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + REQUIRE_NOT_NULL(checkable); + REQUIRE_NOT_NULL(cr); + CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); Host::Ptr host; diff --git a/lib/methods/nullchecktask.cpp b/lib/methods/nullchecktask.cpp index 64d64b034..df99c338e 100644 --- a/lib/methods/nullchecktask.cpp +++ b/lib/methods/nullchecktask.cpp @@ -32,9 +32,12 @@ using namespace icinga; 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) { + REQUIRE_NOT_NULL(checkable); + REQUIRE_NOT_NULL(cr); + if (resolvedMacros && !useResolvedMacros) return; @@ -47,5 +50,5 @@ void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult: })); cr->SetState(ServiceOK); - service->ProcessCheckResult(cr); + checkable->ProcessCheckResult(cr); } diff --git a/lib/methods/nulleventtask.cpp b/lib/methods/nulleventtask.cpp index d37e8a7b0..e515d31e8 100644 --- a/lib/methods/nulleventtask.cpp +++ b/lib/methods/nulleventtask.cpp @@ -25,5 +25,7 @@ using namespace icinga; 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); +} diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 18928fa20..b98eec4a7 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -36,6 +36,9 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, PluginCheck, &PluginCheckTask::ScriptFunc, void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + REQUIRE_NOT_NULL(checkable); + REQUIRE_NOT_NULL(cr); + CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); Host::Ptr host; diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 48b8881c2..b8d5d7afe 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -36,6 +36,8 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, PluginEvent, &PluginEventTask::ScriptFunc, void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + REQUIRE_NOT_NULL(checkable); + EventCommand::Ptr commandObj = checkable->GetEventCommand(); Host::Ptr host; diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 4e98aa4fb..c33d29e55 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -39,6 +39,9 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { + REQUIRE_NOT_NULL(notification); + REQUIRE_NOT_NULL(user); + NotificationCommand::Ptr commandObj = notification->GetCommand(); auto type = static_cast(itype); diff --git a/lib/methods/randomchecktask.cpp b/lib/methods/randomchecktask.cpp index 0f55745f9..bdf2d54d4 100644 --- a/lib/methods/randomchecktask.cpp +++ b/lib/methods/randomchecktask.cpp @@ -31,9 +31,12 @@ using namespace icinga; 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) { + REQUIRE_NOT_NULL(checkable); + REQUIRE_NOT_NULL(cr); + if (resolvedMacros && !useResolvedMacros) return; @@ -58,5 +61,5 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul cr->SetState(static_cast(Utility::Random() % 4)); - service->ProcessCheckResult(cr); + checkable->ProcessCheckResult(cr); } diff --git a/lib/methods/timeperiodtask.cpp b/lib/methods/timeperiodtask.cpp index cc4e9b51c..152139e38 100644 --- a/lib/methods/timeperiodtask.cpp +++ b/lib/methods/timeperiodtask.cpp @@ -25,14 +25,18 @@ using namespace icinga; REGISTER_SCRIPTFUNCTION_NS(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate, "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(); 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; for (long t = begin / 60 - 1; t * 60 < end; t++) { diff --git a/lib/remote/eventqueue.cpp b/lib/remote/eventqueue.cpp index 80fd16059..756c9b9a8 100644 --- a/lib/remote/eventqueue.cpp +++ b/lib/remote/eventqueue.cpp @@ -41,7 +41,7 @@ void EventQueue::ProcessEvent(const Dictionary::Ptr& event) frame.Sandboxed = true; try { - if (!FilterUtility::EvaluateFilter(frame, &*m_Filter, event, "event")) + if (!FilterUtility::EvaluateFilter(frame, m_Filter.get(), event, "event")) return; } catch (const std::exception& ex) { Log(LogWarning, "EventQueue") diff --git a/lib/remote/jsonrpcconnection-pki.cpp b/lib/remote/jsonrpcconnection-pki.cpp index 31fa9078a..80740ac31 100644 --- a/lib/remote/jsonrpcconnection-pki.cpp +++ b/lib/remote/jsonrpcconnection-pki.cpp @@ -40,9 +40,6 @@ REGISTER_APIFUNCTION(UpdateCertificate, pki, &UpdateCertificateHandler); Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) { - if (!params) - return Empty; - String certText = params->Get("cert_request"); std::shared_ptr cert; diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index 574cb007f..c1895934c 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -225,7 +225,11 @@ void JsonRpcConnection::MessageHandler(const String& jsonString) Log(LogNotice, "JsonRpcConnection") << "Call to non-existent function '" << method << "' from endpoint '" << m_Identity << "'."; } 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) { /* 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) { - if (!params) - return Empty; - double log_position = params->Get("log_position"); Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();