Quote remote commands in SSH execution to prevent shell interpretation of special characters

This commit is contained in:
Bastian (BaM)
2025-09-14 20:16:27 +02:00
parent eb83c4ccbd
commit 94da305b17

View File

@@ -44,7 +44,8 @@ function ssh_module.execute(command, user, host, port, identity_file)
-- Pass remote command as provided; caller is responsible for proper quoting -- Pass remote command as provided; caller is responsible for proper quoting
table.insert(pieces, "--") table.insert(pieces, "--")
table.insert(pieces, command) -- Quote the remote command to prevent shell interpretation of && and ||
table.insert(pieces, "'" .. command:gsub("'", "'\\''") .. "'")
-- Join with spaces for os.execute -- Join with spaces for os.execute
local function join(args) local function join(args)
@@ -97,7 +98,8 @@ function ssh_module.execute_with_output(command, user, host, port, identity_file
-- Pass remote command as provided -- Pass remote command as provided
table.insert(pieces, "--") table.insert(pieces, "--")
table.insert(pieces, command) -- Quote the remote command to prevent shell interpretation of && and ||
table.insert(pieces, "'" .. command:gsub("'", "'\\''") .. "'")
-- Join with spaces for io.popen -- Join with spaces for io.popen
local function join(args) local function join(args)