Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe usage of popen #6490

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deepspeed/utils/numa.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def check_for_numactl_pkg():
flag, lib, tool = data
path = distutils.spawn.find_executable(pkgmgr)
if path is not None:
cmd = f"{pkgmgr} {flag} {lib}"
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
cmd = [pkgmgr, flag, lib]
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.wait() == 0:
found = True
else:
Expand Down
4 changes: 2 additions & 2 deletions op_builder/async_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def check_for_libaio_pkg(self):
flag, lib, tool = data
path = distutils.spawn.find_executable(pkgmgr)
if path is not None:
cmd = f"{pkgmgr} {flag} {lib}"
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
cmd = [pkgmgr, flag, lib]
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.wait() == 0:
found = True
else:
Expand Down
3 changes: 2 additions & 1 deletion op_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ def command_exists(self, cmd):
cmds = [cmd]
valid = False
for cmd in cmds:
result = subprocess.Popen(f'type {cmd}', stdout=subprocess.PIPE, shell=True)
safe_cmd = ["bash", "-c", f"type {cmd}"]
result = subprocess.Popen(safe_cmd, stdout=subprocess.PIPE)
valid = valid or result.wait() == 0

if not valid and len(cmds) > 1:
Expand Down
4 changes: 2 additions & 2 deletions op_builder/npu/async_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def check_for_libaio_pkg(self):
flag, lib, tool = data
path = distutils.spawn.find_executable(pkgmgr)
if path is not None:
cmd = f"{pkgmgr} {flag} {lib}"
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
cmd = [pkgmgr, flag, lib]
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.wait() == 0:
found = True
else:
Expand Down
4 changes: 2 additions & 2 deletions op_builder/xpu/async_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def check_for_libaio_pkg(self):
flag, lib, tool = data
path = distutils.spawn.find_executable(pkgmgr)
if path is not None:
cmd = f"{pkgmgr} {flag} {lib}"
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
cmd = [pkgmgr, flag, lib]
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.wait() == 0:
found = True
else:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def command_exists(cmd):
result = subprocess.Popen(f'{cmd}', stdout=subprocess.PIPE, shell=True)
return result.wait() == 1
else:
result = subprocess.Popen(f'type {cmd}', stdout=subprocess.PIPE, shell=True)
safe_cmd = ["bash", "-c", f"type {cmd}"]
result = subprocess.Popen(safe_cmd, stdout=subprocess.PIPE)
return result.wait() == 0


Expand Down
Loading