Skip to content

Commit 129d303

Browse files
committed
Fix DOS attack from malicious pongs
A double channel close panic was possible if a peer sent back multiple pongs for every ping. If the second pong arrived before the ping goroutine deleted its channel from the map, the channel would be closed twice and so a panic would ensue. This fixes that by having the read goroutine send on the ping goroutine's channel rather than closing it. Reported via email by Tibor Kálmán @kalmant Please update to the new release ASAP!
1 parent e4c3b0f commit 129d303

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

conn_notjs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (c *Conn) Ping(ctx context.Context) error {
189189
}
190190

191191
func (c *Conn) ping(ctx context.Context, p string) error {
192-
pong := make(chan struct{})
192+
pong := make(chan struct{}, 1)
193193

194194
c.activePingsMu.Lock()
195195
c.activePings[p] = pong

read.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) {
271271
pong, ok := c.activePings[string(b)]
272272
c.activePingsMu.Unlock()
273273
if ok {
274-
close(pong)
274+
select {
275+
case pong <- struct{}{}:
276+
default:
277+
}
275278
}
276279
return nil
277280
}

0 commit comments

Comments
 (0)