Skip to content

Commit f109943

Browse files
authored
fix semgrep issues for dgryski.semgrep-go ruleset (#3541)
* fix semgrep issues dgryski.semgrep-go ruleset Signed-off-by: Dmitry S <dsavints@gmail.com> * golangci-lint: check error value of out.Write() Signed-off-by: Dmitry S <dsavints@gmail.com> --------- Signed-off-by: Dmitry S <dsavints@gmail.com>
1 parent 92e7fa9 commit f109943

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

cmd/cosign/cli/download/sbom.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ func SBOMCmd(
100100
}
101101

102102
sboms = append(sboms, string(sbom))
103-
fmt.Fprint(out, string(sbom))
103+
if _, err := out.Write(sbom); err != nil {
104+
return nil, err
105+
}
104106

105107
return sboms, nil
106108
}

cmd/cosign/cli/generate/generate.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package generate
1717

1818
import (
1919
"context"
20-
"fmt"
2120
"io"
2221

2322
"github.com/google/go-containerregistry/pkg/name"
@@ -49,6 +48,6 @@ func GenerateCmd(ctx context.Context, regOpts options.RegistryOptions, imageRef
4948
if err != nil {
5049
return err
5150
}
52-
fmt.Fprint(w, string(json))
51+
w.Write(json)
5352
return nil
5453
}

cmd/cosign/cli/verify/verify_blob.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"errors"
2525
"fmt"
2626
"io"
27+
"io/fs"
2728
"os"
2829
"path/filepath"
2930

@@ -313,7 +314,7 @@ func base64signature(sigRef, bundlePath string) (string, error) {
313314
case sigRef != "":
314315
targetSig, err = blob.LoadFileOrURL(sigRef)
315316
if err != nil {
316-
if !os.IsNotExist(err) {
317+
if !errors.Is(err, fs.ErrNotExist) {
317318
// ignore if file does not exist, it can be a base64 encoded string as well
318319
return "", err
319320
}

internal/pkg/cosign/common.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"errors"
1919
"hash"
2020
"io"
21+
"io/fs"
2122
"os"
2223
)
2324

@@ -27,7 +28,7 @@ const (
2728

2829
func FileExists(filename string) (bool, error) {
2930
info, err := os.Stat(filename)
30-
if os.IsNotExist(err) {
31+
if errors.Is(err, fs.ErrNotExist) {
3132
return false, nil
3233
}
3334
if err != nil {

pkg/cosign/verify.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"encoding/json"
2828
"encoding/pem"
2929
"fmt"
30+
"io/fs"
3031
"net/http"
3132
"os"
3233
"regexp"
@@ -834,7 +835,7 @@ func loadSignatureFromFile(ctx context.Context, sigRef string, signedImgRef name
834835
var b64sig string
835836
targetSig, err := blob.LoadFileOrURL(sigRef)
836837
if err != nil {
837-
if !os.IsNotExist(err) {
838+
if !errors.Is(err, fs.ErrNotExist) {
838839
return nil, err
839840
}
840841
targetSig = []byte(sigRef)

pkg/providers/interface.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Provide(ctx context.Context, audience string) (string, error) {
8080
}
8181
id, err = provider.p.Provide(ctx, audience)
8282
if err == nil {
83-
return id, err
83+
return id, nil
8484
}
8585
}
8686
// return the last id/err combo, unless there wasn't an error in

0 commit comments

Comments
 (0)