From 15f812b10f2aac277ac2f571d229b562fc4965c6 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 8 Jun 2018 13:24:59 -0700 Subject: [PATCH] lnwire: don't attempt to decode an empty/nil signature --- lnwire/signature.go | 8 ++++++++ rpcserver.go | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lnwire/signature.go b/lnwire/signature.go index accacac8..67bfc3bb 100644 --- a/lnwire/signature.go +++ b/lnwire/signature.go @@ -17,6 +17,10 @@ type Sig [64]byte func NewSigFromRawSignature(sig []byte) (Sig, error) { var b Sig + if len(sig) == 0 { + return b, fmt.Errorf("cannot decode empty signature") + } + // Extract lengths of R and S. The DER representation is laid out as // 0x30 0x02 r 0x02 s // which means the length of R is the 4th byte and the length of S @@ -61,6 +65,10 @@ func NewSigFromRawSignature(sig []byte) (Sig, error) { // NewSigFromSignature creates a new signature as used on the wire, from an // existing btcec.Signature. func NewSigFromSignature(e *btcec.Signature) (Sig, error) { + if e == nil { + return Sig{}, fmt.Errorf("cannot decode empty signature") + } + // Serialize the signature with all the checks that entails. return NewSigFromRawSignature(e.Serialize()) } diff --git a/rpcserver.go b/rpcserver.go index 7d56b739..8383b6e0 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2186,7 +2186,6 @@ func (r *rpcServer) sendPayment(stream *paymentStream) error { PaymentRoute: marshallRoute(route), }) if err != nil { - rpcsLog.Infof("sender rrrrr: ", err) errChan <- err return }