diff options
author | Leo Chen <leo@harmony.one> | 2019-02-15 03:51:02 +0800 |
---|---|---|
committer | Leo Chen <leo@harmony.one> | 2019-02-15 03:59:48 +0800 |
commit | 5dba8cba5a767dff835bac9609eddaf9d2ee6db3 (patch) | |
tree | ed168b1ffe4e1d99518d92ede6be9ec1ef1f1648 /ffi/go | |
parent | 0693d342069b100cf53867c39c7d4e837bcdc366 (diff) | |
download | dexon-bls-5dba8cba5a767dff835bac9609eddaf9d2ee6db3.tar dexon-bls-5dba8cba5a767dff835bac9609eddaf9d2ee6db3.tar.gz dexon-bls-5dba8cba5a767dff835bac9609eddaf9d2ee6db3.tar.bz2 dexon-bls-5dba8cba5a767dff835bac9609eddaf9d2ee6db3.tar.lz dexon-bls-5dba8cba5a767dff835bac9609eddaf9d2ee6db3.tar.xz dexon-bls-5dba8cba5a767dff835bac9609eddaf9d2ee6db3.tar.zst dexon-bls-5dba8cba5a767dff835bac9609eddaf9d2ee6db3.zip |
check nil pointer before calling to C functions
this will prevent program crash when null public key were passed into
the function calls.
Signed-off-by: Leo Chen <leo@harmony.one>
Diffstat (limited to 'ffi/go')
-rw-r--r-- | ffi/go/bls/bls.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/ffi/go/bls/bls.go b/ffi/go/bls/bls.go index a5c657c..425a68c 100644 --- a/ffi/go/bls/bls.go +++ b/ffi/go/bls/bls.go @@ -323,6 +323,9 @@ func (sign *Sign) Verify(pub *PublicKey, m string) bool { // VerifyPop -- func (sign *Sign) VerifyPop(pub *PublicKey) bool { + if pub.getPointer() == nil { + return false + } return C.blsVerifyPop(sign.getPointer(), pub.getPointer()) == 1 } @@ -345,6 +348,9 @@ func HashAndMapToSignature(buf []byte) *Sign { // VerifyPairing -- func VerifyPairing(X *Sign, Y *Sign, pub *PublicKey) bool { + if X.getPointer() == nil || Y.getPointer() == nil || pub.getPointer() == nil { + return false + } return C.blsVerifyPairing(X.getPointer(), Y.getPointer(), pub.getPointer()) == 1 } @@ -363,6 +369,9 @@ func (sec *SecretKey) SignHash(hash []byte) (sign *Sign) { // VerifyHash -- func (sign *Sign) VerifyHash(pub *PublicKey, hash []byte) bool { // #nosec + if pub.getPointer() == nil { + return false + } return C.blsVerifyHash(sign.getPointer(), pub.getPointer(), unsafe.Pointer(&hash[0]), C.size_t(len(hash))) == 1 } @@ -382,5 +391,8 @@ func (sign *Sign) VerifyAggregateHashes(pubVec []PublicKey, hash [][]byte) bool hn := len(hash[i]) copy(h[i*hashByte:(i+1)*hashByte], hash[i][0:Min(hn, hashByte)]) } + if pubVec[0].getPointer() == nil { + return false + } return C.blsVerifyAggregatedHashes(sign.getPointer(), pubVec[0].getPointer(), unsafe.Pointer(&h[0]), C.size_t(hashByte), C.size_t(n)) == 1 } |