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