Module: check_mk
Branch: master
Commit: d3381cad5e060cbcb5b29e3a162b84b09d83da06
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d3381cad5e060c…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Tue Jan 9 14:45:10 2018 +0100
Windows agent: make sure eventlog name is present
While parsing statefile, check for missing or empty eventlog name.
Change-Id: I44c8e1e86bb62b27292ad7e7c9f1e95ea1f72631
---
agents/windows/build_version | 2 +-
agents/windows/sections/SectionEventlog.cc | 4 +++-
agents/windows/test/sections/SectionEventlogTest.cc | 7 +++++--
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/agents/windows/build_version b/agents/windows/build_version
index b2fffd3..70ca397 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3044
+3046
diff --git a/agents/windows/sections/SectionEventlog.cc
b/agents/windows/sections/SectionEventlog.cc
index ecd6aa8..f10e7b8 100644
--- a/agents/windows/sections/SectionEventlog.cc
+++ b/agents/windows/sections/SectionEventlog.cc
@@ -37,7 +37,9 @@ eventlog_hint_t parseStateLine(const std::string &line) {
/* Example: line = "System|1234" */
const auto tokens = tokenize(line, "\\|");
- if (tokens.size() != 2) {
+ if (tokens.size() != 2 ||
+ std::any_of(tokens.cbegin(), tokens.cend(),
+ [](const std::string &t) { return t.empty(); })) {
throw StateParseError{std::string("Invalid state line: ") + line};
}
diff --git a/agents/windows/test/sections/SectionEventlogTest.cc
b/agents/windows/test/sections/SectionEventlogTest.cc
index 71174ed..32bbaed 100644
--- a/agents/windows/test/sections/SectionEventlogTest.cc
+++ b/agents/windows/test/sections/SectionEventlogTest.cc
@@ -27,6 +27,11 @@ TEST_F(wa_SectionEventlogTest, parseStateLine_Application_valid) {
ASSERT_EQ(expected, parseStateLine(line));
}
+TEST_F(wa_SectionEventlogTest, parseStateLine_Application_missing_name) {
+ char line[] = "|19881";
+ ASSERT_THROW(parseStateLine(line), StateParseError);
+}
+
TEST_F(wa_SectionEventlogTest, parseStateLine_Application_missing_value) {
char line[] = "Application|";
ASSERT_THROW(parseStateLine(line), StateParseError);
@@ -59,7 +64,5 @@ TEST_F(wa_SectionEventlogTest,
parseStateLine_Internet_Explorer_negative) {
TEST_F(wa_SectionEventlogTest,
parseStateLine_Internet_Explorer_conversion_error) {
char line[] = "Internet Explorer|garbage";
- const eventlog_hint_t expected{
- "Internet Explorer", std::numeric_limits<unsigned long
long>::max()};
ASSERT_THROW(parseStateLine(line), StateParseError);
}