From bb5e69f8db952893f78471f73f8a48d48eba0933 Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Fri, 4 Oct 2024 10:47:34 -0300 Subject: [PATCH] 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 --- utils/apparmor/logparser.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/apparmor/logparser.py b/utils/apparmor/logparser.py index 2316f7fa1..823b3712a 100644 --- a/utils/apparmor/logparser.py +++ b/utils/apparmor/logparser.py @@ -18,6 +18,7 @@ import sys import time import LibAppArmor +import apparmor.ui as aaui from apparmor.common import AppArmorBug, AppArmorException, DebugLogger, hasher, open_file_read, split_name from apparmor.rule.capability import CapabilityRule from apparmor.rule.change_profile import ChangeProfileRule @@ -274,7 +275,11 @@ class ReadLog: """Parse the event from log into key value pairs""" msg = msg.strip() self.debug_logger.info('parse_event: %s', 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 = self.parse_record(event) LibAppArmor.free_record(event)