diff --git a/dnscrypt-proxy/common.go b/dnscrypt-proxy/common.go index c3f268d5..7387aa89 100644 --- a/dnscrypt-proxy/common.go +++ b/dnscrypt-proxy/common.go @@ -1,15 +1,17 @@ package main import ( + "bytes" "encoding/binary" "errors" "fmt" + "io/ioutil" "net" + "os" "runtime" "strconv" "strings" "unicode" - "os" ) type CryptoConstruction uint16 @@ -38,7 +40,7 @@ var ( ) var ( - FileDescriptors = make([]*os.File, 0) + FileDescriptors = make([]*os.File, 0) FileDescriptorNum = 0 ) @@ -170,3 +172,12 @@ func MemUsage() { fmt.Printf("\tSys = %v MiB", m.Sys/1024/1024) fmt.Printf("\tNumGC = %v\n", m.NumGC) } + +func ReadTextFile(filename string) (string, error) { + bin, err := ioutil.ReadFile(filename) + if err != nil { + return "", err + } + bin = bytes.TrimPrefix(bin, []byte{0xef, 0xbb, 0xbf}) + return string(bin), nil +} diff --git a/dnscrypt-proxy/plugin_block_ip.go b/dnscrypt-proxy/plugin_block_ip.go index 3d8590d9..6e669cd4 100644 --- a/dnscrypt-proxy/plugin_block_ip.go +++ b/dnscrypt-proxy/plugin_block_ip.go @@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "io/ioutil" "net" "strings" "time" @@ -32,7 +31,7 @@ func (plugin *PluginBlockIP) Description() string { func (plugin *PluginBlockIP) Init(proxy *Proxy) error { dlog.Noticef("Loading the set of IP blocking rules from [%s]", proxy.blockIPFile) - bin, err := ioutil.ReadFile(proxy.blockIPFile) + bin, err := ReadTextFile(proxy.blockIPFile) if err != nil { return err } diff --git a/dnscrypt-proxy/plugin_block_name.go b/dnscrypt-proxy/plugin_block_name.go index 07f14b3c..1d6785c8 100644 --- a/dnscrypt-proxy/plugin_block_name.go +++ b/dnscrypt-proxy/plugin_block_name.go @@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "io/ioutil" "net" "strings" "time" @@ -31,7 +30,7 @@ func (plugin *PluginBlockName) Description() string { func (plugin *PluginBlockName) Init(proxy *Proxy) error { dlog.Noticef("Loading the set of blocking rules from [%s]", proxy.blockNameFile) - bin, err := ioutil.ReadFile(proxy.blockNameFile) + bin, err := ReadTextFile(proxy.blockNameFile) if err != nil { return err } diff --git a/dnscrypt-proxy/plugin_cloak.go b/dnscrypt-proxy/plugin_cloak.go index 885d8c9d..8058f00a 100644 --- a/dnscrypt-proxy/plugin_cloak.go +++ b/dnscrypt-proxy/plugin_cloak.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "net" "strings" "sync" @@ -36,7 +35,7 @@ func (plugin *PluginCloak) Description() string { func (plugin *PluginCloak) Init(proxy *Proxy) error { dlog.Noticef("Loading the set of cloaking rules from [%s]", proxy.cloakFile) - bin, err := ioutil.ReadFile(proxy.cloakFile) + bin, err := ReadTextFile(proxy.cloakFile) if err != nil { return err } diff --git a/dnscrypt-proxy/plugin_forward.go b/dnscrypt-proxy/plugin_forward.go index f878bf58..aa63bb8c 100644 --- a/dnscrypt-proxy/plugin_forward.go +++ b/dnscrypt-proxy/plugin_forward.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "math/rand" "net" "strings" @@ -31,7 +30,7 @@ func (plugin *PluginForward) Description() string { func (plugin *PluginForward) Init(proxy *Proxy) error { dlog.Noticef("Loading the set of forwarding rules from [%s]", proxy.forwardFile) - bin, err := ioutil.ReadFile(proxy.forwardFile) + bin, err := ReadTextFile(proxy.forwardFile) if err != nil { return err } diff --git a/dnscrypt-proxy/plugin_whitelist_name.go b/dnscrypt-proxy/plugin_whitelist_name.go index 1e235970..6af856ec 100644 --- a/dnscrypt-proxy/plugin_whitelist_name.go +++ b/dnscrypt-proxy/plugin_whitelist_name.go @@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "io/ioutil" "net" "strings" "time" @@ -31,7 +30,7 @@ func (plugin *PluginWhitelistName) Description() string { func (plugin *PluginWhitelistName) Init(proxy *Proxy) error { dlog.Noticef("Loading the set of whitelisting rules from [%s]", proxy.whitelistNameFile) - bin, err := ioutil.ReadFile(proxy.whitelistNameFile) + bin, err := ReadTextFile(proxy.whitelistNameFile) if err != nil { return err }