Skip to content

Commit bd44611

Browse files
authored
Fix panic building policy (#243)
This commit fixes a panic creating policies for repos with controls enabled Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]>
1 parent ece1d4b commit bd44611

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

sourcetool/pkg/slsa/slsa_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type Controls []*provenance.Control
6666
// Adds the control to the list. Ignores nil controls.
6767
// Does not check for duplicate controls.
6868
func (controls *Controls) AddControl(newControls ...*provenance.Control) {
69+
if controls == nil {
70+
controls = &Controls{}
71+
}
6972
for _, c := range newControls {
7073
if c == nil {
7174
continue

sourcetool/pkg/sourcetool/tool.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,12 @@ func (t *Tool) CreateBranchPolicy(ctx context.Context, r *models.Repository, bra
204204
return nil, fmt.Errorf("could not get provenance for latest commit: %w", err)
205205
}
206206

207-
var controls *slsa.Controls
207+
controls := &slsa.Controls{}
208208
if predicate != nil {
209209
for _, c := range predicate.GetControls() {
210210
controls.AddControl(c)
211211
}
212212
}
213-
214213
return t.createPolicy(r, branches[0], controls)
215214
}
216215

0 commit comments

Comments
 (0)