Quote remote commands in SSH execution to prevent shell interpretation of special characters
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user