Skip to content

Commit

Permalink
lava_callback.py: Sanitize lava log data
Browse files Browse the repository at this point in the history
As we use this data in reports, lets remove all
non-printable characters as they confuse grafana, browsers and others.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed May 31, 2024
1 parent 1895ddb commit 3c2b63c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lava_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def _upload_log(log_parser, job_node, storage):
data = log_parser.get_text()
if not data or len(data) == 0:
return None
# Delete NULL characters from log data
data = data.replace('\x00', '')
# Sanitize log data from non-printable characters (except newline)
# replace them with '?', original still exists in cb data
data = ''.join([c if c.isprintable() or c == '\n' else
'?' for c in data])
f.write(data)
src = os.path.join(tmp_dir, 'lava_log.txt.gz')
return _upload_file(storage, job_node, src, 'log.txt.gz')
Expand Down

0 comments on commit 3c2b63c

Please sign in to comment.