From 8e3559c3b12684802a98afa115cc22d5725d4586 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Wed, 15 Jul 2015 12:26:19 -0700 Subject: [PATCH 1/2] Guard against uninitialized pointers in io.Copy to fix #2416 --- communicator/winrm/communicator.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/communicator/winrm/communicator.go b/communicator/winrm/communicator.go index d90cd8450..1efd770e0 100644 --- a/communicator/winrm/communicator.go +++ b/communicator/winrm/communicator.go @@ -85,8 +85,13 @@ func (c *Communicator) Start(rc *packer.RemoteCmd) error { func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *packer.RemoteCmd) { defer shell.Close() - go io.Copy(rc.Stdout, cmd.Stdout) - go io.Copy(rc.Stderr, cmd.Stderr) + if rc.Stdout != nil && cmd.Stdout != nil { + go io.Copy(rc.Stdout, cmd.Stdout) + } + + if rc.Stderr != nil && cmd.Stderr != nil { + go io.Copy(rc.Stderr, cmd.Stderr) + } cmd.Wait() From 29e6194e49ea76ae8556231389a8d18822d40948 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Wed, 15 Jul 2015 12:29:42 -0700 Subject: [PATCH 2/2] Added a warning log so we can diagnose failure cases --- communicator/winrm/communicator.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/communicator/winrm/communicator.go b/communicator/winrm/communicator.go index 1efd770e0..59034fcf0 100644 --- a/communicator/winrm/communicator.go +++ b/communicator/winrm/communicator.go @@ -87,10 +87,14 @@ func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *packer.RemoteCmd) { if rc.Stdout != nil && cmd.Stdout != nil { go io.Copy(rc.Stdout, cmd.Stdout) + } else { + log.Printf("[WARN] Failed to read stdout for command '%s'", rc.Command) } if rc.Stderr != nil && cmd.Stderr != nil { go io.Copy(rc.Stderr, cmd.Stderr) + } else { + log.Printf("[WARN] Failed to read stderr for command '%s'", rc.Command) } cmd.Wait()