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

fix semgrep issues for dgryski.semgrep-go ruleset #3541

Merged
merged 2 commits into from
Feb 15, 2024
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
4 changes: 3 additions & 1 deletion cmd/cosign/cli/download/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func SBOMCmd(
}

sboms = append(sboms, string(sbom))
fmt.Fprint(out, string(sbom))
if _, err := out.Write(sbom); err != nil {
return nil, err
}

return sboms, nil
}
3 changes: 1 addition & 2 deletions cmd/cosign/cli/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package generate

import (
"context"
"fmt"
"io"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -49,6 +48,6 @@ func GenerateCmd(ctx context.Context, regOpts options.RegistryOptions, imageRef
if err != nil {
return err
}
fmt.Fprint(w, string(json))
w.Write(json)
dmitris marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
3 changes: 2 additions & 1 deletion cmd/cosign/cli/verify/verify_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"

Expand Down Expand Up @@ -313,7 +314,7 @@ func base64signature(sigRef, bundlePath string) (string, error) {
case sigRef != "":
targetSig, err = blob.LoadFileOrURL(sigRef)
if err != nil {
if !os.IsNotExist(err) {
if !errors.Is(err, fs.ErrNotExist) {
// ignore if file does not exist, it can be a base64 encoded string as well
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/cosign/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"hash"
"io"
"io/fs"
"os"
)

Expand All @@ -27,7 +28,7 @@ const (

func FileExists(filename string) (bool, error) {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
if errors.Is(err, fs.ErrNotExist) {
return false, nil
}
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"io/fs"
"net/http"
"os"
"regexp"
Expand Down Expand Up @@ -834,7 +835,7 @@ func loadSignatureFromFile(ctx context.Context, sigRef string, signedImgRef name
var b64sig string
targetSig, err := blob.LoadFileOrURL(sigRef)
if err != nil {
if !os.IsNotExist(err) {
if !errors.Is(err, fs.ErrNotExist) {
return nil, err
}
targetSig = []byte(sigRef)
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Provide(ctx context.Context, audience string) (string, error) {
}
id, err = provider.p.Provide(ctx, audience)
if err == nil {
return id, err
return id, nil
}
}
// return the last id/err combo, unless there wasn't an error in
Expand Down
Loading