Module: check_mk
Branch: master
Commit: 6606c929adcbcd4535ce8e29bfd628646ae4f2c3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6606c929adcbcd…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Feb 5 15:39:20 2016 +0100
#3164 FIX No longer crash on action or email if trap contains a null byte
---
.bugs/2319 | 6 ++++--
.werks/3164 | 9 +++++++++
ChangeLog | 1 +
mkeventd/bin/mkeventd | 14 ++++++++++----
4 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/.bugs/2319 b/.bugs/2319
index 2fae989..c82d3bd 100644
--- a/.bugs/2319
+++ b/.bugs/2319
@@ -1,9 +1,11 @@
Title: Event Console actions fail on non printable chars in event
Component: ec
-State: open
+Class: bug
+State: done
Date: 2015-10-29 09:45:52
Targetversion: 1.2.8
-Class: bug
When e.g. a trap contains a \0, eventually raised script
actions fail with an exception in the event console.
+
+2016-02-05 15:38:58: changed state open -> done
diff --git a/.werks/3164 b/.werks/3164
new file mode 100644
index 0000000..9698080
--- /dev/null
+++ b/.werks/3164
@@ -0,0 +1,9 @@
+Title: No longer crash on action or email if trap contains a null byte
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.2.7i4
+Date: 1454683140
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index 1a61316..6f8662b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -374,6 +374,7 @@
* 2862 FIX: Fixed handling of umlauts in mails send by the EC
* 2893 FIX: Improved error handling of sending mails via Event Console
* 2986 FIX: Event Console: Text elements of events are now correctly quoted in shell
scripts...
+ * 3164 FIX: No longer crash on action or email if trap contains a null byte
Livestatus:
* 2743 FIX: Fixed handling of column types in "GET columns"...
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 5b5471d..dbfb787 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -3276,6 +3276,10 @@ def get_quoted_event(event):
return new_event
+def escape_null_bytes(s):
+ return s.replace("\000", "\\000")
+
+
def do_event_action(action, event, user=""):
if action["disabled"]:
log("Skipping disabled action %s." % action["id"])
@@ -3284,13 +3288,13 @@ def do_event_action(action, event, user=""):
try:
action_type, settings = action["action"]
if action_type == 'email':
- to = substitute_event_tags(settings["to"], event)
- subject = substitute_event_tags(settings["subject"], event)
- body = substitute_event_tags(settings["body"], event)
+ to = escape_null_bytes(substitute_event_tags(settings["to"],
event))
+ subject =
escape_null_bytes(substitute_event_tags(settings["subject"], event))
+ body = escape_null_bytes(substitute_event_tags(settings["body"],
event))
send_email(to, subject, body)
log_event_history(event, "EMAIL", user, "%s|%s" % (to,
subject))
elif action_type == 'script':
- execute_script(substitute_event_tags(settings["script"],
get_quoted_event(event)))
+
execute_script(escape_null_bytes(substitute_event_tags(settings["script"],
get_quoted_event(event))))
log_event_history(event, "SCRIPT", user, action['id'])
else:
log("Cannot execute action %s: invalid action type %s" %
(action["id"], action_type))
@@ -3434,6 +3438,8 @@ def send_email(to, subject, body):
def execute_script(body):
+ # Traps can contain 0-Bytes. We need to remove this from the script
+ # body. Otherwise suprocess.Popen will crash.
p = subprocess.Popen(
body.encode('utf-8'),
shell = True,