Merge pull request #244 from mrd0ll4r/udp-fix-ip-spoofing

udp: fix IP bytes not being copied out of the packet
This commit is contained in:
mrd0ll4r 2016-10-04 21:31:32 +02:00 committed by GitHub
commit 9c9b4a5002
2 changed files with 8 additions and 2 deletions

View file

@ -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))

View file

@ -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.