mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 13:44:31 +00:00
Merge pull request #341 from XinFinOrg/fix-CVE-2023-40591
fix-CVE-2023-40591
This commit is contained in:
commit
8be49a4ca1
1 changed files with 13 additions and 2 deletions
15
p2p/peer.go
15
p2p/peer.go
|
|
@ -105,6 +105,7 @@ type Peer struct {
|
|||
wg sync.WaitGroup
|
||||
protoErr chan error
|
||||
closed chan struct{}
|
||||
pingRecv chan struct{}
|
||||
disc chan DiscReason
|
||||
|
||||
// events receives message send / receive events if set
|
||||
|
|
@ -175,6 +176,7 @@ func newPeer(conn *conn, protocols []Protocol) *Peer {
|
|||
disc: make(chan DiscReason),
|
||||
protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop
|
||||
closed: make(chan struct{}),
|
||||
pingRecv: make(chan struct{}, 16),
|
||||
log: log.New("id", conn.id, "conn", conn.flags),
|
||||
}
|
||||
return p
|
||||
|
|
@ -236,9 +238,11 @@ loop:
|
|||
}
|
||||
|
||||
func (p *Peer) pingLoop() {
|
||||
ping := time.NewTimer(pingInterval)
|
||||
defer p.wg.Done()
|
||||
|
||||
ping := time.NewTimer(pingInterval)
|
||||
defer ping.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ping.C:
|
||||
|
|
@ -247,6 +251,10 @@ func (p *Peer) pingLoop() {
|
|||
return
|
||||
}
|
||||
ping.Reset(pingInterval)
|
||||
|
||||
case <-p.pingRecv:
|
||||
SendItems(p.rw, pongMsg)
|
||||
|
||||
case <-p.closed:
|
||||
return
|
||||
}
|
||||
|
|
@ -273,7 +281,10 @@ func (p *Peer) handle(msg Msg) error {
|
|||
switch {
|
||||
case msg.Code == pingMsg:
|
||||
msg.Discard()
|
||||
go SendItems(p.rw, pongMsg)
|
||||
select {
|
||||
case p.pingRecv <- struct{}{}:
|
||||
case <-p.closed:
|
||||
}
|
||||
case msg.Code == discMsg:
|
||||
var reason [1]DiscReason
|
||||
// This is the last message. We don't need to discard or
|
||||
|
|
|
|||
Loading…
Reference in a new issue