Skip BOMs in configuration files

Fixes #613
This commit is contained in:
Frank Denis 2018-10-15 17:56:04 +02:00
parent 4192e2fff7
commit 99133f53ef
6 changed files with 18 additions and 12 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}