File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 4242import re
4343import signal
4444import shutil
45+ import string
4546import subprocess
4647import sys
4748import tempfile
@@ -233,7 +234,6 @@ def to_cmd_str(cmd):
233234 work_dir = os .getcwd ()
234235
235236 cmd_str = to_cmd_str (cmd )
236- cmd_name = os .path .basename (cmd_str .split (' ' )[0 ])
237237
238238 # auto-enable streaming of command output under --logtostdout/-l, unless it was disabled explicitely
239239 if stream_output is None and build_option ('logtostdout' ):
@@ -244,6 +244,9 @@ def to_cmd_str(cmd):
244244 if output_file :
245245 toptmpdir = os .path .join (tempfile .gettempdir (), 'run-shell-cmd-output' )
246246 os .makedirs (toptmpdir , exist_ok = True )
247+ # restrict the allowed characters in the name of the output_file
248+ allowed_chars = string .ascii_letters + string .digits
249+ cmd_name = '' .join ([c for c in os .path .basename (cmd_str .split (' ' )[0 ]) if c in allowed_chars ])
247250 tmpdir = tempfile .mkdtemp (dir = toptmpdir , prefix = f'{ cmd_name } -' )
248251 cmd_out_fp = os .path .join (tmpdir , 'out.txt' )
249252 _log .info (f'run_cmd: Output of "{ cmd_str } " will be logged to { cmd_out_fp } ' )
You can’t perform that action at this time.
0 commit comments