Skip to content

Commit a36b02d

Browse files
authored
Merge pull request #3688 from orbisai0security/fix-fix-shell-injection-subprocess-call
fix: sanitize subprocess call in generate_snapshots.py
2 parents 33045c3 + 6876a78 commit a36b02d

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

tests/snapshots/generate_snapshots.py

100755100644
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import pathlib
66
import shutil
7+
from typing import Iterable
78

89

910
def generate_snapshots():
@@ -19,22 +20,23 @@ def generate_snapshots():
1920

2021

2122
def generate_style_snapshot(style):
22-
generate_snapshot(style.replace(",", "_"), "--style={}".format(style))
23+
generate_snapshot(style.replace(",", "_"), ["--style={}".format(style)])
2324

2425

25-
def generate_snapshot(name, arguments):
26-
command = "cargo run -- --paging=never --color=never --decorations=always "
27-
command += "{args} sample.rs > output/{name}.snapshot.txt".format(
28-
name=name,
29-
args=arguments
30-
)
26+
def generate_snapshot(name: str, arguments: Iterable[str]):
27+
output_file = "output/{name}.snapshot.txt".format(name=name)
28+
command = [
29+
"cargo", "run", "--", "--paging=never", "--color=never",
30+
"--decorations=always", *arguments, "sample.rs"
31+
]
3132
print("generating snapshot for {}".format(name))
32-
subprocess.call(command, shell=True)
33+
with open(output_file, "w") as f:
34+
subprocess.call(command, stdout=f)
3335

3436

3537
def build_bat():
3638
print("building bat")
37-
subprocess.call("cargo build", cwd="../..", shell=True)
39+
subprocess.call(["cargo", "build"], cwd="../..")
3840

3941

4042
def prepare_output_dir():
@@ -49,7 +51,7 @@ def modify_sample_file():
4951

5052
def undo_sample_file_modification():
5153
print("undoing sample.rs modifications")
52-
subprocess.call("git checkout -- sample.rs", shell=True)
54+
subprocess.call(["git", "checkout", "--", "sample.rs"])
5355

5456

5557
build_bat()

0 commit comments

Comments
 (0)