Skip to content

Commit 22e12b4

Browse files
authored
allow only alphanumeric characters in the output filename
1 parent 360b053 commit 22e12b4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

easybuild/tools/run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import re
4343
import signal
4444
import shutil
45+
import string
4546
import subprocess
4647
import sys
4748
import 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}')

0 commit comments

Comments
 (0)