From b515cab53502ce083b88b37bb09c64e4df2b738a Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Tue, 19 Mar 2024 11:05:30 -0400 Subject: [PATCH] Fix incorrect slice addressing Slice was being filtered but the loop counter wasn't being modified ``` panic: runtime error: index out of range [1] with length 1 goroutine 8 [running]: /Users/sean/go/src/github.com/pion/mdns/conn.go:965 +0xb9c /Users/sean/go/src/github.com/pion/mdns/conn.go:976 +0x1e4 /Users/sean/go/src/github.com/pion/mdns/conn.go:1018 +0x90 /Users/sean/go/src/github.com/pion/mdns/conn.go:1013 +0x234 ``` --- conn.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index e2774a4..f25ac55 100644 --- a/conn.go +++ b/conn.go @@ -961,10 +961,11 @@ func (c *Conn) readLoop(name string, pktConn ipPacketConn, inboundBufferSize int c.mu.Lock() for queryIdx := len(c.queries) - 1; queryIdx >= 0; queryIdx-- { for answerIdx := len(answered) - 1; answerIdx >= 0; answerIdx-- { - answer := answered[answerIdx] - if c.queries[queryIdx] == answer { + if c.queries[queryIdx] == answered[answerIdx] { c.queries = append(c.queries[:queryIdx], c.queries[queryIdx+1:]...) answered = append(answered[:answerIdx], answered[answerIdx+1:]...) + queryIdx-- + break } } }