From 506c98e7528a7c5ff63c1e6060ab9ee77ac03944 Mon Sep 17 00:00:00 2001 From: John Johansen Date: Thu, 17 Oct 2024 18:56:25 +0000 Subject: [PATCH] Merge utils: catch TypeError exception for binary logs When a log like system.journal is passed on to aa-genprof, for example, the user receives a TypeError exception: in method 'parse_record', argument 1 of type 'char *' This patch catches that exception and displays a more meaningful message. Fixes: https://gitlab.com/apparmor/apparmor/-/issues/436 Signed-off-by: Georgia Garcia Closes #436 MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1354 Approved-by: Christian Boltz Merged-by: John Johansen (cherry picked from commit cb0f84e1014e0c002735381f09a929ef4dff892c) Signed-off-by: Georgia Garcia --- utils/apparmor/logparser.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/apparmor/logparser.py b/utils/apparmor/logparser.py index 230372159..f97600897 100644 --- a/utils/apparmor/logparser.py +++ b/utils/apparmor/logparser.py @@ -17,6 +17,7 @@ import re import sys import time import LibAppArmor +import apparmor.ui as aaui from apparmor.common import AppArmorException, AppArmorBug, open_file_read, DebugLogger from apparmor.aamode import validate_log_mode, log_str_to_mode, hide_log_mode, AA_MAY_EXEC @@ -95,7 +96,13 @@ class ReadLog: if sys.version_info < (3, 0): # parse_record fails with u'foo' style strings hence typecasting to string msg = str(msg) - event = LibAppArmor.parse_record(msg) + + try: + event = LibAppArmor.parse_record(msg) + except TypeError: + aaui.UI_Important(_("WARNING: Cannot process log message, skipping entry. Make sure log is plaintext.")) + return None + ev = dict() ev['resource'] = event.info ev['active_hat'] = event.active_hat