mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
fix: nil dereference on handshakeAuthData
This commit is contained in:
parent
67a3b08795
commit
a383fea2dd
1 changed files with 18 additions and 5 deletions
|
|
@ -504,27 +504,34 @@ func (c *Codec) decodeWhoareyou(head *Header, headerData []byte) (Packet, error)
|
||||||
func (c *Codec) decodeHandshakeMessage(fromAddr string, head *Header, headerData, msgData []byte) (n *enode.Node, p Packet, err error) {
|
func (c *Codec) decodeHandshakeMessage(fromAddr string, head *Header, headerData, msgData []byte) (n *enode.Node, p Packet, err error) {
|
||||||
node, auth, session, err := c.decodeHandshake(fromAddr, head)
|
node, auth, session, err := c.decodeHandshake(fromAddr, head)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if auth != nil && auth.isHandshakeAuthDataValid() {
|
||||||
c.sc.deleteHandshake(auth.h.SrcID, fromAddr)
|
c.sc.deleteHandshake(auth.h.SrcID, fromAddr)
|
||||||
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrypt the message using the new session keys.
|
// Decrypt the message using the new session keys.
|
||||||
msg, err := c.decryptMessage(msgData, head.Nonce[:], headerData, session.readKey)
|
msg, err := c.decryptMessage(msgData, head.Nonce[:], headerData, session.readKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if auth != nil && auth.isHandshakeAuthDataValid() {
|
||||||
c.sc.deleteHandshake(auth.h.SrcID, fromAddr)
|
c.sc.deleteHandshake(auth.h.SrcID, fromAddr)
|
||||||
|
}
|
||||||
return node, msg, err
|
return node, msg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handshake OK, drop the challenge and store the new session keys.
|
// Handshake OK, drop the challenge and store the new session keys.
|
||||||
c.sc.storeNewSession(auth.h.SrcID, fromAddr, session)
|
c.sc.storeNewSession(auth.h.SrcID, fromAddr, session)
|
||||||
c.sc.deleteHandshake(auth.h.SrcID, fromAddr)
|
c.sc.deleteHandshake(auth.h.SrcID, fromAddr)
|
||||||
|
|
||||||
return node, msg, nil
|
return node, msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Codec) decodeHandshake(fromAddr string, head *Header) (n *enode.Node, auth handshakeAuthData, s *session, err error) {
|
func (c *Codec) decodeHandshake(fromAddr string, head *Header) (n *enode.Node, auth *handshakeAuthData, s *session, err error) {
|
||||||
if auth, err = c.decodeHandshakeAuthData(head); err != nil {
|
var tempAuth handshakeAuthData
|
||||||
return nil, auth, nil, err
|
if tempAuth, err = c.decodeHandshakeAuthData(head); err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
auth = &tempAuth
|
||||||
|
|
||||||
// Verify against our last WHOAREYOU.
|
// Verify against our last WHOAREYOU.
|
||||||
challenge := c.sc.getHandshake(auth.h.SrcID, fromAddr)
|
challenge := c.sc.getHandshake(auth.h.SrcID, fromAddr)
|
||||||
|
|
@ -670,3 +677,9 @@ func bytesCopy(r *bytes.Buffer) []byte {
|
||||||
copy(b, r.Bytes())
|
copy(b, r.Bytes())
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isHandshakeAuthDataValid checks if handshakeAuthData is valid
|
||||||
|
func (auth *handshakeAuthData) isHandshakeAuthDataValid() bool {
|
||||||
|
// Conditions for the auth to be considered valid
|
||||||
|
return auth != nil && len(auth.signature) > 0 && len(auth.pubkey) > 0 && auth.h.SrcID != (enode.ID{})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue