Skip to content

Commit 442d894

Browse files
Peter Dragunrplevka
authored andcommitted
escape command quotes
1 parent 8226ca8 commit 442d894

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

broker/session.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import socket
3+
import tempfile
34
from pathlib import Path
45
from logzero import logger
56
from ssh2.session import Session as ssh2_Session
@@ -200,6 +201,12 @@ def run(self, command, demux=True, **kwargs):
200201
"""This is the container approximation of Session.run"""
201202
kwargs.pop("timeout", None) # Timeouts are set at the client level
202203
kwargs["demux"] = demux
204+
if "'" in command:
205+
with tempfile.NamedTemporaryFile(mode="w", suffix=".sh") as tmp:
206+
tmp.write(command)
207+
tmp.seek(0)
208+
command = f"/bin/bash {tmp.name}"
209+
self.sftp_write(tmp.name)
203210
if any([s in command for s in "|&><"]):
204211
# Containers don't handle pipes, redirects, etc well in a bare exec_run
205212
command = f"/bin/bash -c '{command}'"

0 commit comments

Comments
 (0)