From: Jason Ish Date: Thu, 15 Sep 2022 15:34:48 +0000 (-0600) Subject: runner: handle binary output from suricata stderr/stdout X-Git-Tag: suricata-6.0.8~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8ff4a83bacada2c222b6bc432b0d3b3469b45f1;p=thirdparty%2Fsuricata-verify.git runner: handle binary output from suricata stderr/stdout 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. --- diff --git a/run.py b/run.py index 56b8bee04..ce3615f78 100755 --- 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)