Browse Source

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

main
Bastian (BaM) 3 months ago
parent
commit
94da305b17
  1. 6
      scripts/ssh.lua

6
scripts/ssh.lua

@ -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)

Loading…
Cancel
Save