Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
gosec: added error handling & path cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Grönqvist committed Dec 13, 2019
1 parent bf2c550 commit 8413219
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"net"
"os"
"path/filepath"

log "github.com/sirupsen/logrus"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
Expand Down Expand Up @@ -43,7 +44,7 @@ func NewServerConfig(cfgPath string) *ServerConfig {
Users: make(map[string]*UserConfig),
}

f, err := os.Open(cfgPath)
f, err := os.Open(filepath.Clean(cfgPath))
if err == nil {
if err = json.NewDecoder(f).Decode(cfg); err != nil {
log.Fatal(err)
Expand Down
15 changes: 12 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strings"
"sync"

"github.com/elazarl/go-bindata-assetfs"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/google/nftables"
"github.com/google/nftables/expr"
"github.com/julienschmidt/httprouter"
Expand Down Expand Up @@ -279,7 +279,10 @@ func (s *Server) configureWireGuard() error {
ReplacePeers: true,
Peers: peers,
}
wg.ConfigureDevice(*wgLinkName, cfg)
err = wg.ConfigureDevice(*wgLinkName, cfg)
if err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -454,7 +457,13 @@ Endpoint = %s
}
w.Header().Set("Content-Type", "image/png")
w.WriteHeader(http.StatusOK)
w.Write(png)
_, err = w.Write(png)
if err != nil {
log.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}

return
}

Expand Down

0 comments on commit 8413219

Please sign in to comment.