From e4f6b6f720207874d84d58d289d5771ced6dae30 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 27 Aug 2018 19:36:40 -0700 Subject: [PATCH] fix chroot communicator to properly escape quotes --- builder/amazon/chroot/communicator.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index 854522caa..8b552d002 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "syscall" @@ -23,8 +24,10 @@ type Communicator struct { } func (c *Communicator) Start(cmd *packer.RemoteCmd) error { + // need extra escapes for the command since we're wrapping it in quotes + cmd.Command = strconv.Quote(cmd.Command) command, err := c.CmdWrapper( - fmt.Sprintf("chroot %s /bin/sh -c \"%s\"", c.Chroot, cmd.Command)) + fmt.Sprintf("chroot %s /bin/sh -c %s", c.Chroot, cmd.Command)) if err != nil { return err }