Skip to content

Commit

Permalink
fix nil pointer deref in cli/upload.BlobCmd (#563)
Browse files Browse the repository at this point in the history
calling 'cosign upload blob ...' with an image address but without any -f arguments lead to a nil pointer dereference; check that at least one file was provided

Signed-off-by: Anton Semjonov <anton@semjonov.de>
  • Loading branch information
ansemjo authored Aug 24, 2021
1 parent 92ce88e commit 8ce7d29
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/cosign/cli/upload/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package upload

import (
"context"
"errors"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -83,7 +84,7 @@ EXAMPLES
`,
FlagSet: flagset,
Exec: func(ctx context.Context, args []string) error {
if len(args) != 1 {
if len(args) != 1 || len(fmap.Files) < 1 {
return flag.ErrHelp
}

Expand All @@ -102,6 +103,9 @@ func BlobCmd(ctx context.Context, files []cremote.File, contentType, imageRef st
if err != nil {
return err
}
if dgster == nil {
return errors.New("dgstr is nil, no files uploaded?")
}
dgst, err := dgster.Digest()
if err != nil {
return err
Expand Down

0 comments on commit 8ce7d29

Please sign in to comment.