diff --git a/frontend/udp/frontend.go b/frontend/udp/frontend.go index 0fe785a..3a74341 100644 --- a/frontend/udp/frontend.go +++ b/frontend/udp/frontend.go @@ -128,10 +128,15 @@ func (t *Frontend) ListenAndServe() error { defer t.wg.Done() defer pool.Put(buffer) + if ip := addr.IP.To4(); ip != nil { + addr.IP = ip + } + // Handle the request. start := time.Now() action, err := t.handleRequest( - Request{buffer[:n], addr.IP}, + // Make sure the IP is copied, not referenced. + Request{buffer[:n], append([]byte{}, addr.IP...)}, ResponseWriter{t.socket, addr}, ) recordResponseDuration(action, err, time.Since(start)) diff --git a/frontend/udp/parser.go b/frontend/udp/parser.go index ccddfff..4474a01 100644 --- a/frontend/udp/parser.go +++ b/frontend/udp/parser.go @@ -80,7 +80,8 @@ func ParseAnnounce(r Request, allowIPSpoofing, v6 bool) (*bittorrent.AnnounceReq ip := r.IP ipbytes := r.Packet[84:ipEnd] if allowIPSpoofing { - ip = net.IP(ipbytes) + // Make sure the bytes are copied to a new slice. + copy(ip, net.IP(ipbytes)) } if !allowIPSpoofing && r.IP == nil { // We have no IP address to fallback on.