diff --git a/pkg/action/list.go b/pkg/action/list.go index 7902837fd..31b9a2f78 100644 --- a/pkg/action/list.go +++ b/pkg/action/list.go @@ -17,6 +17,7 @@ limitations under the License. package action import ( + "errors" "path" "regexp" @@ -151,6 +152,12 @@ func (l *List) Run() ([]ri.Releaser, error) { return nil, err } + // A negative offset would otherwise panic in the slice expression below, + // as the out-of-bounds guard only covers offsets past the end of the list. + if l.Offset < 0 { + return nil, errors.New("list offset cannot be negative") + } + var filter *regexp.Regexp if l.Filter != "" { var err error diff --git a/pkg/action/list_test.go b/pkg/action/list_test.go index 1c849028d..ac25a2866 100644 --- a/pkg/action/list_test.go +++ b/pkg/action/list_test.go @@ -179,6 +179,15 @@ func TestList_LimitOffsetOutOfBounds(t *testing.T) { is.Len(list, 2) } +func TestList_NegativeOffset(t *testing.T) { + req := require.New(t) + lister := newListFixture(t) + lister.Offset = -1 + makeMeSomeReleases(t, lister.cfg.Releases) + _, err := lister.Run() + req.Error(err) +} + func TestList_StateMask(t *testing.T) { is := assert.New(t) req := require.New(t)