Fix: mutable SplitAddr cause panic

This commit is contained in:
gVisor bot 2020-03-02 23:47:23 +08:00
parent b50da85dbb
commit ad85f0934a
2 changed files with 14 additions and 2 deletions

View file

@ -216,6 +216,11 @@ func (spc *ssPacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
return 0, nil, errors.New("parse addr error")
}
udpAddr := addr.UDPAddr()
if udpAddr == nil {
return 0, nil, errors.New("parse addr error")
}
copy(b, b[len(addr):])
return n - len(addr), addr.UDPAddr(), e
return n - len(addr), udpAddr, e
}

View file

@ -3,6 +3,7 @@ package outbound
import (
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"io/ioutil"
@ -169,9 +170,15 @@ func (uc *socksPacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
if err != nil {
return 0, nil, err
}
udpAddr := addr.UDPAddr()
if udpAddr == nil {
return 0, nil, errors.New("parse udp addr error")
}
// due to DecodeUDPPacket is mutable, record addr length
copy(b, payload)
return n - len(addr) - 3, addr.UDPAddr(), nil
return n - len(addr) - 3, udpAddr, nil
}
func (uc *socksPacketConn) Close() error {