gosec: added error handling & path cleaning

This commit is contained in:
Fredrik Grönqvist
2019-12-13 12:51:22 +01:00
parent bf2c550334
commit 8413219dec
2 changed files with 14 additions and 4 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"io/ioutil"
"net"
"os"
"path/filepath"
log "github.com/sirupsen/logrus"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
@@ -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)
+12 -3
View File
@@ -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"
@@ -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
}
@@ -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
}