Quote any file paths that we have to use with dd to copy.

This is because we pass the whole dd command string into the shell
that's running on the contained environment rather than running it
directly from python via subprocess without a shell.
pull/12626/head
Toshio Kuratomi 9 years ago
parent b83988d9fb
commit 10a4a4e986

@ -22,6 +22,7 @@ __metaclass__ = type
import distutils.spawn import distutils.spawn
import os import os
import os.path import os.path
import pipes
import subprocess import subprocess
import traceback import traceback
@ -117,7 +118,7 @@ class Connection(ConnectionBase):
super(Connection, self).put_file(in_path, out_path) super(Connection, self).put_file(in_path, out_path)
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.chroot) self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.chroot)
out_path = self._prefix_login_path(out_path) out_path = pipes.quote(self._prefix_login_path(out_path))
try: try:
with open(in_path, 'rb') as in_file: with open(in_path, 'rb') as in_file:
try: try:
@ -139,7 +140,7 @@ class Connection(ConnectionBase):
super(Connection, self).fetch_file(in_path, out_path) super(Connection, self).fetch_file(in_path, out_path)
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.chroot) self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.chroot)
in_path = self._prefix_login_path(in_path) in_path = pipes.quote(self._prefix_login_path(in_path))
try: try:
p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE)) p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
except OSError: except OSError:

@ -27,6 +27,7 @@ __metaclass__ = type
import distutils.spawn import distutils.spawn
import os import os
import os.path import os.path
import pipes
import subprocess import subprocess
import re import re
@ -154,6 +155,7 @@ class Connection(ConnectionBase):
if p.returncode != 0: if p.returncode != 0:
raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr)) raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
else: else:
out_path = pipes.quote(out_path)
# Older docker doesn't have native support for copying files into # Older docker doesn't have native support for copying files into
# running containers, so we use docker exec to implement this # running containers, so we use docker exec to implement this
executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh' executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh'

@ -23,6 +23,7 @@ __metaclass__ = type
import distutils.spawn import distutils.spawn
import os import os
import os.path import os.path
import pipes
import subprocess import subprocess
import traceback import traceback
@ -144,7 +145,7 @@ class Connection(ConnectionBase):
super(Connection, self).put_file(in_path, out_path) super(Connection, self).put_file(in_path, out_path)
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.jail) self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.jail)
out_path = self._prefix_login_path(out_path) out_path = pipes.quote(self._prefix_login_path(out_path))
try: try:
with open(in_path, 'rb') as in_file: with open(in_path, 'rb') as in_file:
try: try:
@ -166,7 +167,7 @@ class Connection(ConnectionBase):
super(Connection, self).fetch_file(in_path, out_path) super(Connection, self).fetch_file(in_path, out_path)
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.jail) self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.jail)
in_path = self._prefix_login_path(in_path) in_path = pipes.quote(self._prefix_login_path(in_path))
try: try:
p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE)) p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
except OSError: except OSError:

@ -23,6 +23,7 @@ __metaclass__ = type
import distutils.spawn import distutils.spawn
import os import os
import os.path import os.path
import pipes
import subprocess import subprocess
from ansible import constants as C from ansible import constants as C
@ -116,7 +117,7 @@ class Connection(ConnectionBase):
super(Connection, self).put_file(in_path, out_path) super(Connection, self).put_file(in_path, out_path)
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.lxc) self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.lxc)
out_path = self._prefix_login_path(out_path) out_path = pipes.quote(self._prefix_login_path(out_path))
try: try:
with open(in_path, 'rb') as in_file: with open(in_path, 'rb') as in_file:
try: try:
@ -138,7 +139,7 @@ class Connection(ConnectionBase):
super(Connection, self).fetch_file(in_path, out_path) super(Connection, self).fetch_file(in_path, out_path)
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.lxc) self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.lxc)
in_path = self._prefix_login_path(in_path) in_path = pipes.quote(self._prefix_login_path(in_path))
try: try:
p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE)) p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
except OSError: except OSError:

@ -24,6 +24,7 @@ __metaclass__ = type
import distutils.spawn import distutils.spawn
import os import os
import os.path import os.path
import pipes
import subprocess import subprocess
import traceback import traceback
@ -157,7 +158,7 @@ class Connection(ConnectionBase):
super(Connection, self).put_file(in_path, out_path) super(Connection, self).put_file(in_path, out_path)
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.zone) self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.zone)
out_path = self._prefix_login_path(out_path) out_path = pipes.quote(self._prefix_login_path(out_path))
try: try:
with open(in_path, 'rb') as in_file: with open(in_path, 'rb') as in_file:
try: try:
@ -179,7 +180,7 @@ class Connection(ConnectionBase):
super(Connection, self).fetch_file(in_path, out_path) super(Connection, self).fetch_file(in_path, out_path)
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.zone) self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.zone)
in_path = self._prefix_login_path(in_path) in_path = pipes.quote(self._prefix_login_path(in_path))
try: try:
p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE)) p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
except OSError: except OSError:

Loading…
Cancel
Save