From 0abf0b948b01a12b7a608fa8df3f6f8a5a457f3d Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Wed, 1 Feb 2023 16:41:03 -0500 Subject: [PATCH] job parsing: fix panic when variable validation is missing condition (#16018) --- .changelog/16018.txt | 3 +++ jobspec2/types.variables.go | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 .changelog/16018.txt diff --git a/.changelog/16018.txt b/.changelog/16018.txt new file mode 100644 index 000000000..2f3355538 --- /dev/null +++ b/.changelog/16018.txt @@ -0,0 +1,3 @@ +```release-note:bug +parser: Fixed a panic in the job spec parser when a variable validation block was missing its condition +``` diff --git a/jobspec2/types.variables.go b/jobspec2/types.variables.go index 8e32ded20..26af20eb6 100644 --- a/jobspec2/types.variables.go +++ b/jobspec2/types.variables.go @@ -95,6 +95,17 @@ func (v *Variable) validateValue(val VariableAssignment) (diags hcl.Diagnostics) for _, validation := range v.Validations { const errInvalidCondition = "Invalid variable validation result" + if validation.Condition == nil { + diags = append(diags, &hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Invalid variable validation specification", + Detail: "validation requires a condition.", + Subject: validation.DeclRange.Ptr(), + EvalContext: hclCtx, + }) + continue + } + result, moreDiags := validation.Condition.Value(hclCtx) diags = append(diags, moreDiags...) if !result.IsKnown() {