Skip to content

Commit

Permalink
FIX validate decode result using regex
Browse files Browse the repository at this point in the history
  • Loading branch information
davcrypto committed Oct 13, 2023
1 parent 5c59a3f commit 9d049e0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion infrastructure/tendermint/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"math/big"
"regexp"
"strconv"
"strings"

Expand All @@ -16,6 +17,10 @@ import (
jsoniter "github.com/json-iterator/go"
)

var (
regxASCII = regexp.MustCompile("^[\x00-\x7F]+$")
)

// Block related parsing functions
func ParseGenesisResp(rawRespReader io.Reader, strictParsing bool) (*genesis.Genesis, error) {
var genesisResp GenesisResp
Expand Down Expand Up @@ -274,8 +279,11 @@ func base64Decode(s string) (string, error) {
decoded, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return "", err
} else if regxASCII.Match(decoded) {
return string(decoded), nil
}
return string(decoded), nil

return "", fmt.Errorf("error `%s` is not base64 encoded", s)
}

func parseBlockResultsConsensusParamsUpdates(rawUpdates RawBlockResultsConsensusParamUpdates) model.BlockResultsConsensusParamUpdates {
Expand Down

0 comments on commit 9d049e0

Please sign in to comment.