]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
runner: make env string safe before substitution 606/head
authorJason Ish <jason.ish@oisf.net>
Sun, 12 Dec 2021 20:18:15 +0000 (14:18 -0600)
committerJason Ish <jason.ish@oisf.net>
Sun, 12 Dec 2021 23:26:54 +0000 (17:26 -0600)
The environment cannot always be used safely with
string.Template as not all environment variables
are string safe.

Before substituting environment vars in the command
and args, sanitized to string safe values.

run.py

diff --git a/run.py b/run.py
index cac453093a73204d9b72f384ab273fb93a55c390..522d953cd27966157627ae29287f2bed8969a040 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -610,6 +610,10 @@ class TestRunner:
 
         env = self.build_env()
 
+        safe_env = {}
+        for key in env:
+            safe_env[key] = str(env[key])
+
         if "count" in self.config:
             count = self.config["count"]
         else:
@@ -633,10 +637,10 @@ class TestRunner:
 
             if shell:
                 template = string.Template(args)
-                cmdline = template.substitute(env)
+                cmdline = template.substitute(safe_env)
             else:
                 for a in range(len(args)):
-                    args[a] = string.Template(args[a]).substitute(env)
+                    args[a] = string.Template(args[a]).substitute(safe_env)
                 cmdline = " ".join(args) + "\n"
 
             open(os.path.join(self.output, "cmdline"), "w").write(cmdline)