mirror of
https://github.com/Threnklyn/wg-ui.git
synced 2026-06-07 14:03:33 +02:00
gosec: added error handling & path cleaning
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user