diff --git a/CHANGELOG.md b/CHANGELOG.md index dcb835f15..be793c167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ BUG FIXES: +* core: Fix crash case if blank parameters are given to Packer. [GH-832] * builders/docker: user variables work properly. [GH-777] * builder/virtualbox,vmware: iso\_checksum is not required if the checksum type is "none" diff --git a/packer/environment.go b/packer/environment.go index 34dd8ba7d..a7067a682 100644 --- a/packer/environment.go +++ b/packer/environment.go @@ -221,7 +221,7 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) { // Trim up to the command name for i, v := range args { - if v[0] != '-' { + if len(v) > 0 && v[0] != '-' { args = args[i:] break } diff --git a/packer/environment_test.go b/packer/environment_test.go index b5ac7b9c8..65bc83057 100644 --- a/packer/environment_test.go +++ b/packer/environment_test.go @@ -198,10 +198,17 @@ func TestEnvironment_Cli_CallsRun(t *testing.T) { func TestEnvironment_DefaultCli_Empty(t *testing.T) { defaultEnv := testEnvironment() + // Test with no args exitCode, _ := defaultEnv.Cli([]string{}) if exitCode != 1 { t.Fatalf("bad: %d", exitCode) } + + // Test with only blank args + exitCode, _ = defaultEnv.Cli([]string{""}) + if exitCode != 1 { + t.Fatalf("bad: %d", exitCode) + } } func TestEnvironment_DefaultCli_Help(t *testing.T) {