Skip to content

Commit

Permalink
Fix HIGH and MED severity gosec warnings
Browse files Browse the repository at this point in the history
- ignore LOW severity gosec warnings
  • Loading branch information
CoinsNaulty committed Jun 30, 2021
1 parent c6be60f commit 56e39c6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ gosec: gosec
docker run --rm -t \
-w /mtail \
-v $(CURDIR):/mtail \
securego/gosec /mtail/...
securego/gosec --exclude=G104 /mtail/...


###
Expand Down
3 changes: 2 additions & 1 deletion cmd/mdot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/golang/glog"
Expand Down Expand Up @@ -131,7 +132,7 @@ func (d *dotter) VisitAfter(node ast.Node) ast.Node {
}

func makeDot(name string, w io.Writer) error {
f, err := os.Open(name)
f, err := os.Open(filepath.Clean(name))
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/mgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func rand(n int) (r int) {
a, _ := crand.Int(crand.Reader, big.NewInt(int64(n)))
r = int(a.Int64())
} else {
/* #nosec G404 */
r = mrand.Intn(n)
}
return
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *Runtime) LoadProgram(programPath string) error {
glog.V(2).Infof("Skipping %s due to file extension.", programPath)
return nil
}
f, err := os.OpenFile(programPath, os.O_RDONLY, 0600)
f, err := os.OpenFile(filepath.Clean(programPath), os.O_RDONLY, 0600)
if err != nil {
ProgLoadErrors.Add(name, 1)
return errors.Wrapf(err, "Failed to read program %q", programPath)
Expand Down
5 changes: 3 additions & 2 deletions internal/testutil/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package testutil
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)

Expand All @@ -27,7 +28,7 @@ func TestTempDir(tb testing.TB) string {
// TestOpenFile creates a new file called name and returns the opened file.
func TestOpenFile(tb testing.TB, name string) *os.File {
tb.Helper()
f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
f, err := os.OpenFile(filepath.Clean(name), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
tb.Fatal(err)
}
Expand All @@ -37,7 +38,7 @@ func TestOpenFile(tb testing.TB, name string) *os.File {
// OpenLogFile creates a new file that emulates being a log.
func OpenLogFile(tb testing.TB, name string) *os.File {
tb.Helper()
f, err := os.OpenFile(name, os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0600)
f, err := os.OpenFile(filepath.Clean(name), os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
tb.Fatal(err)
}
Expand Down

0 comments on commit 56e39c6

Please sign in to comment.