mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-16 07:20:58 +00:00
fix: panic under some stupid input config
This commit is contained in:
parent
4b15568a29
commit
487d7fa81f
2 changed files with 12 additions and 5 deletions
|
@ -20,16 +20,19 @@ func (o RealityOptions) Parse() (*tlsC.RealityConfig, error) {
|
|||
config := new(tlsC.RealityConfig)
|
||||
|
||||
const x25519ScalarSize = 32
|
||||
var publicKey [x25519ScalarSize]byte
|
||||
n, err := base64.RawURLEncoding.Decode(publicKey[:], []byte(o.PublicKey))
|
||||
if err != nil || n != x25519ScalarSize {
|
||||
publicKey, err := base64.RawURLEncoding.DecodeString(o.PublicKey)
|
||||
if err != nil || len(publicKey) != x25519ScalarSize {
|
||||
return nil, errors.New("invalid REALITY public key")
|
||||
}
|
||||
config.PublicKey, err = ecdh.X25519().NewPublicKey(publicKey[:])
|
||||
config.PublicKey, err = ecdh.X25519().NewPublicKey(publicKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fail to create REALITY public key: %w", err)
|
||||
}
|
||||
|
||||
n := hex.DecodedLen(len(o.ShortID))
|
||||
if n > tlsC.RealityMaxShortIDLen {
|
||||
return nil, errors.New("invalid REALITY short id")
|
||||
}
|
||||
n, err = hex.Decode(config.ShortID[:], []byte(o.ShortID))
|
||||
if err != nil || n > tlsC.RealityMaxShortIDLen {
|
||||
return nil, errors.New("invalid REALITY short ID")
|
||||
|
|
|
@ -50,7 +50,11 @@ func (c Config) Build() (*Builder, error) {
|
|||
realityConfig.ShortIds = make(map[[8]byte]bool)
|
||||
for i, shortIDString := range c.ShortID {
|
||||
var shortID [8]byte
|
||||
decodedLen, err := hex.Decode(shortID[:], []byte(shortIDString))
|
||||
decodedLen := hex.DecodedLen(len(shortIDString))
|
||||
if decodedLen > 8 {
|
||||
return nil, fmt.Errorf("invalid short_id[%d]: %s", i, shortIDString)
|
||||
}
|
||||
decodedLen, err = hex.Decode(shortID[:], []byte(shortIDString))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decode short_id[%d] '%s': %w", i, shortIDString, err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue