]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
runner: handle binary output from suricata stderr/stdout
authorJason Ish <jason.ish@oisf.net>
Thu, 15 Sep 2022 15:34:48 +0000 (09:34 -0600)
committerJason Ish <jason.ish@oisf.net>
Fri, 16 Sep 2022 22:07:02 +0000 (16:07 -0600)
Don't attempt to decode output from Suricata stderr/stdout as utf-8, it
is required for relaying the output from Suricata to the log files,
in fact, its not even desired.  The log files should have a verbatim
copy of the output for analysis.

Only attempt to utf-8 decode the output when logging in verbose mode,
and then if that fails, fallback to logging the data as a byte buffer.

run.py

diff --git a/run.py b/run.py
index 56b8bee04fb365f57798a60e9713dc4c196e6c9e..ce3615f780aa2d89096a273e5aa70b2ab6cec654 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -137,12 +137,15 @@ def get_suricata_version():
 
 def pipe_reader(fileobj, output=None, verbose=False):
     for line in fileobj:
-        line = line.decode()
         if output:
             output.write(line)
             output.flush()
         if verbose:
-            print(line.strip())
+            try:
+                line = line.decode().strip()
+            except:
+                pass
+            print(line)
 
 
 def handle_exceptions(func):
@@ -650,8 +653,8 @@ class TestRunner:
             os.makedirs(self.output)
             self.setup()
 
-            stdout = open(os.path.join(self.output, "stdout"), "w")
-            stderr = open(os.path.join(self.output, "stderr"), "w")
+            stdout = open(os.path.join(self.output, "stdout"), "wb")
+            stderr = open(os.path.join(self.output, "stderr"), "wb")
 
             if shell:
                 template = string.Template(args)