diff --git a/common/bytes.go b/common/bytes.go index d1f5c6c995..060ecfc955 100644 --- a/common/bytes.go +++ b/common/bytes.go @@ -77,13 +77,25 @@ func Bytes2Hex(d []byte) string { // Hex2Bytes returns the bytes represented by the hexadecimal string str. func Hex2Bytes(str string) []byte { - h, _ := hex.DecodeString(str) + if !isHex(str) { + return nil + } + h, err := hex.DecodeString(str) + if err != nil { + return nil + } return h } // Hex2BytesFixed returns bytes of a specified fixed length flen. func Hex2BytesFixed(str string, flen int) []byte { - h, _ := hex.DecodeString(str) + if !isHex(str) { + return make([]byte, flen) + } + h, err := hex.DecodeString(str) + if err != nil { + return make([]byte, flen) + } if len(h) == flen { return h } diff --git a/common/path.go b/common/path.go index 841946348e..5dd10b026f 100644 --- a/common/path.go +++ b/common/path.go @@ -44,6 +44,9 @@ func IsNonEmptyDir(dir string) bool { return false } defer f.Close() - names, _ := f.Readdirnames(1) + names, err := f.Readdirnames(1) + if err != nil { + return false + } return len(names) > 0 }