check for 0 length strings in pubkey parser.

We check length later, but we assumed it was always 1 bytes long. Not
always the case. I'm a little depressed that this bug was there.
This commit is contained in:
Owain G. Ainsworth 2014-03-17 17:47:27 +00:00
parent ff3fac426d
commit de670bd5b2

View file

@ -6,6 +6,7 @@ package btcec
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"errors"
"fmt" "fmt"
"math/big" "math/big"
) )
@ -53,6 +54,10 @@ func ParsePubKey(pubKeyStr []byte, curve *KoblitzCurve) (key *ecdsa.PublicKey, e
pubkey := ecdsa.PublicKey{} pubkey := ecdsa.PublicKey{}
pubkey.Curve = curve pubkey.Curve = curve
if len(pubKeyStr) == 0 {
return nil, errors.New("pubkey string is empty")
}
format := pubKeyStr[0] format := pubKeyStr[0]
ybit := (format & 0x1) == 0x1 ybit := (format & 0x1) == 0x1
format &= ^byte(0x1) format &= ^byte(0x1)