Skip to content
Open
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
11 changes: 4 additions & 7 deletions src/openllm/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,17 @@ async def async_run_command(

proc = None
try:
proc = await asyncio.create_subprocess_shell(
' '.join(map(str, cmd)),
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=cwd,
env=env,
proc = await asyncio.create_subprocess_exec(
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, cwd=cwd, env=env
)
yield proc
except subprocess.CalledProcessError:
output('Command failed', style='red')
raise typer.Exit(1)
finally:
if proc:
proc.send_signal(signal.SIGINT)
if proc.returncode is None:
proc.send_signal(signal.SIGINT)
await proc.wait()


Expand Down
23 changes: 23 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import asyncio
import os

from openllm.common import async_run_command


def test_async_run_command_does_not_invoke_shell(tmp_path):
marker = tmp_path / 'shell_injection_marker.txt'
if os.name == 'nt':
separator = '&'
payload = ['cmd', '/c', f'echo PWNED>{marker}']
else:
separator = ';'
payload = ['sh', '-c', f'echo PWNED > {marker}']
Comment on lines +3 to +14

async def run() -> None:
cmd = ['python', '-c', 'pass', separator, *payload]
async with async_run_command(cmd, cwd=str(tmp_path), silent=True) as proc:
await proc.wait()

asyncio.run(run())

assert not marker.exists()