Merge pull request #3688 from orbisai0security/fix-fix-shell-injection-subprocess-call

fix: sanitize subprocess call in generate_snapshots.py
This commit is contained in:
Keith Hall authored and GitHub committed 2026-04-12 16:04:47 +03:00
commit a36b02d90f
1 file changed
+12 -10
Vendored Executable → Regular
+12 -10
View File
@@ -4,6 +4,7 @@ import itertools
import subprocess import subprocess
import pathlib import pathlib
import shutil import shutil
from typing import Iterable
def generate_snapshots(): def generate_snapshots():
@@ -19,22 +20,23 @@ def generate_snapshots():
def generate_style_snapshot(style): def generate_style_snapshot(style):
generate_snapshot(style.replace(",", "_"), "--style={}".format(style)) generate_snapshot(style.replace(",", "_"), ["--style={}".format(style)])
def generate_snapshot(name, arguments): def generate_snapshot(name: str, arguments: Iterable[str]):
command = "cargo run -- --paging=never --color=never --decorations=always " output_file = "output/{name}.snapshot.txt".format(name=name)
command += "{args} sample.rs > output/{name}.snapshot.txt".format( command = [
name=name, "cargo", "run", "--", "--paging=never", "--color=never",
args=arguments "--decorations=always", *arguments, "sample.rs"
) ]
print("generating snapshot for {}".format(name)) print("generating snapshot for {}".format(name))
subprocess.call(command, shell=True) with open(output_file, "w") as f:
subprocess.call(command, stdout=f)
def build_bat(): def build_bat():
print("building bat") print("building bat")
subprocess.call("cargo build", cwd="../..", shell=True) subprocess.call(["cargo", "build"], cwd="../..")
def prepare_output_dir(): def prepare_output_dir():
@@ -49,7 +51,7 @@ def modify_sample_file():
def undo_sample_file_modification(): def undo_sample_file_modification():
print("undoing sample.rs modifications") print("undoing sample.rs modifications")
subprocess.call("git checkout -- sample.rs", shell=True) subprocess.call(["git", "checkout", "--", "sample.rs"])
build_bat() build_bat()