Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCL2: fix a crash when an HCL2 component is nil after a misconfiguration #11382

Merged
merged 5 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions command/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ func TestBuild(t *testing.T) {
},
},
},

{
name: "hcl - test crash #11381",
args: []string{
testFixture("hcl", "nil-component-crash.pkr.hcl"),
},
expectedCode: 1,
},
}

for _, tt := range tc {
Expand Down
10 changes: 10 additions & 0 deletions command/test-fixtures/hcl/nil-component-crash.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source "null" "basic-example" {
}

build {
sources = ["sources.null.basic-example"]

provisioner "foo" {
timeout = "10"
}
}
7 changes: 5 additions & 2 deletions hcl2template/types.build.provisioners.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (p *Parser) decodeProvisioner(block *hcl.Block, cfg *PackerConfig) (*Provis
Summary: "Failed to parse pause_before duration",
Severity: hcl.DiagError,
Detail: err.Error(),
Subject: &block.DefRange,
})
}
provisioner.PauseBefore = pauseBefore
Expand All @@ -131,8 +132,10 @@ func (p *Parser) decodeProvisioner(block *hcl.Block, cfg *PackerConfig) (*Provis
timeout, err := time.ParseDuration(b.Timeout)
if err != nil {
return nil, append(diags, &hcl.Diagnostic{
Summary: "Failed to parse timeout duration",
Detail: err.Error(),
Summary: "Failed to parse timeout duration",
Severity: hcl.DiagError,
Detail: err.Error(),
Subject: &block.DefRange,
})
}
provisioner.Timeout = timeout
Expand Down