From 5c6d780f8ceed6761b20ffadbd2bff99ceafbea9 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 26 Nov 2019 21:44:46 +0100 Subject: [PATCH] logging, throw an exception when logfile doesn't look like a clog file, makes it easier to auto-detect clog/plain logs --- src/opnsense/site-python/log_helper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/opnsense/site-python/log_helper.py b/src/opnsense/site-python/log_helper.py index 40b268594..9c0a91bca 100644 --- a/src/opnsense/site-python/log_helper.py +++ b/src/opnsense/site-python/log_helper.py @@ -85,6 +85,8 @@ def fetch_clog(input_log): mm = mmap.mmap(fd.fileno(), 0) # unpack clog information struct clog_footer = struct.unpack('iiii', mm[-16:]) # cf_magic, cf_wrap, cf_next, cf_max, cf_lock + if mm[-20:-16] != b'CLOG': + raise Exception('not a valid clog file') # concat log file into new output stream, start at current wrap position output_stream = StringIO(mm[clog_footer[1]:-20].decode() + mm[:clog_footer[1]].decode()) output_stream.seek(0)