Skip to content

Commit 64bd3c3

Browse files
tjruwaseloadams
authored andcommitted
Avoid security issues of subprocess shell (deepspeedai#6498)
Avoid security issues of `shell=True` in subprocess --------- Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com>
1 parent dc38b77 commit 64bd3c3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

op_builder/builder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ def get_rocm_gpu_arch():
261261
rocm_info = Path("rocminfo")
262262
rocm_gpu_arch_cmd = str(rocm_info) + " | grep -o -m 1 'gfx.*'"
263263
try:
264-
result = subprocess.check_output(rocm_gpu_arch_cmd, shell=True)
264+
safe_cmd = shlex.split(rocm_gpu_arch_cmd)
265+
result = subprocess.check_output(safe_cmd)
265266
rocm_gpu_arch = result.decode('utf-8').strip()
266267
except subprocess.CalledProcessError:
267268
rocm_gpu_arch = ""
@@ -279,7 +280,8 @@ def get_rocm_wavefront_size():
279280
rocm_wavefront_size_cmd = str(
280281
rocm_info) + " | grep -Eo -m1 'Wavefront Size:[[:space:]]+[0-9]+' | grep -Eo '[0-9]+'"
281282
try:
282-
result = subprocess.check_output(rocm_wavefront_size_cmd, shell=True)
283+
safe_cmd = shlex.split(rocm_wavefront_size_cmd)
284+
result = subprocess.check_output(rocm_wavefront_size_cmd)
283285
rocm_wavefront_size = result.decode('utf-8').strip()
284286
except subprocess.CalledProcessError:
285287
rocm_wavefront_size = "32"

0 commit comments

Comments
 (0)