mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
ss: handle unexpect situation to avoid panic #132
This commit is contained in:
1 parent
4e1cb6ebf6
commit
2520a1c8b4
7 files changed
+33
-16
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package socks5
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
"github.com/nadoo/glider/common/log"
|
||||
@@ -57,6 +58,10 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
return n, raddr, err
|
||||
}
|
||||
|
||||
if n < socks.MinAddrLen {
|
||||
return n, raddr, errors.New("not enough size to get addr")
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc1928#section-7
|
||||
// +----+------+------+----------+----------+----------+
|
||||
// |RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA |
|
||||
@@ -64,6 +69,9 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
// | 2 | 1 | 1 | Variable | 2 | Variable |
|
||||
// +----+------+------+----------+----------+----------+
|
||||
tgtAddr := socks.SplitAddr(buf[3:])
|
||||
if tgtAddr == nil {
|
||||
return n, raddr, errors.New("can not get addr")
|
||||
}
|
||||
copy(b, buf[3+len(tgtAddr):])
|
||||
|
||||
//test
|
||||
|
||||
Reference in new issue
Block a user