From 3c852311e1e6e8c05e2ae37484250546fecb010a Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 11 May 2016 16:12:09 +0200 Subject: [PATCH] Fix possible crash in Add{Comment,Downtime} refs #11112 --- lib/compat/externalcommandlistener.cpp | 2 +- lib/icinga/comment.cpp | 3 +++ lib/icinga/downtime.cpp | 4 +++- lib/icinga/externalcommandprocessor.cpp | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/compat/externalcommandlistener.cpp b/lib/compat/externalcommandlistener.cpp index aac24ecc5..dcd57eb3f 100644 --- a/lib/compat/externalcommandlistener.cpp +++ b/lib/compat/externalcommandlistener.cpp @@ -144,7 +144,7 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath) ExternalCommandProcessor::Execute(command); } catch (const std::exception& ex) { Log(LogWarning, "ExternalCommandListener") - << "External command failed." << DiagnosticInformation(ex); + << "External command failed: " << DiagnosticInformation(ex); } } } diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index eeb7b2b60..fd98ae120 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -195,6 +195,9 @@ String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryTyp Comment::Ptr comment = Comment::GetByName(fullName); + if (!comment) + BOOST_THROW_EXCEPTION(std::runtime_error("Could not create comment.")); + Log(LogNotice, "Comment") << "Added comment '" << comment->GetName() << "'."; diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index eaa2e9ba2..66b6a635e 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -251,12 +251,14 @@ String Downtime::AddDowntime(const Checkable::Ptr& checkable, const String& auth Downtime::Ptr downtime = Downtime::GetByName(fullName); + if (!downtime) + BOOST_THROW_EXCEPTION(std::runtime_error("Could not create downtime.")); + Log(LogNotice, "Downtime") << "Added downtime '" << downtime->GetName() << "' between '" << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", startTime) << "' and '" << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", endTime) << "'."; - return fullName; } diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 6d1711d08..c9c921c41 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -1210,7 +1210,7 @@ void ExternalCommandProcessor::AddHostComment(double, const std::vector& BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot add host comment for non-existent host '" + arguments[0] + "'")); if (arguments[2].IsEmpty() || arguments[3].IsEmpty()) - BOOST_THROW_EXCEPTION(std::invalid_argument("Author and comment may not be empty")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Author and comment must not be empty")); Log(LogNotice, "ExternalCommandProcessor") << "Creating comment for host " << host->GetName(); @@ -1234,7 +1234,7 @@ void ExternalCommandProcessor::AddSvcComment(double, const std::vector& BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot add service comment for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'")); if (arguments[3].IsEmpty() || arguments[4].IsEmpty()) - BOOST_THROW_EXCEPTION(std::invalid_argument("Author and comment may not be empty")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Author and comment must not be empty")); Log(LogNotice, "ExternalCommandProcessor") << "Creating comment for service " << service->GetName();