summaryrefslogtreecommitdiff
path: root/common/socks5
diff options
context:
space:
mode:
Diffstat (limited to 'common/socks5')
-rw-r--r--common/socks5/auth_pt2.go14
-rw-r--r--common/socks5/rfc1929.go4
-rw-r--r--common/socks5/socks5.go24
3 files changed, 22 insertions, 20 deletions
diff --git a/common/socks5/auth_pt2.go b/common/socks5/auth_pt2.go
index ce3a50d..7e22a0f 100644
--- a/common/socks5/auth_pt2.go
+++ b/common/socks5/auth_pt2.go
@@ -35,24 +35,24 @@ import (
func (req *Request) authPT2() (err error) {
// The client sends a PT 2.0 authentication request.
- // uint32_t len
- // uint8_t data[len]
+ // uint32_t u
+ // uint8_t data[u]
// Read the authentication data.
- var len uint32
- if len, err = req.readUint32(); err != nil {
+ var u uint32
+ if u, err = req.readUint32(); err != nil {
return
}
- if len == 0 {
+ if u == 0 {
err = fmt.Errorf("PT 2.0 authentication data with 0 length")
return
}
var data []byte
- if data, err = req.readBytes(int(len)); err != nil {
+ if data, err = req.readBytes(int(u)); err != nil {
return
}
- var result string = string(data)
+ var result = string(data)
// Parse the authentication data according to the PT 2.0 specification
if req.Args, err = pt.ParsePT2ClientParameters(result); err != nil {
diff --git a/common/socks5/rfc1929.go b/common/socks5/rfc1929.go
index f8176f1..d7849df 100644
--- a/common/socks5/rfc1929.go
+++ b/common/socks5/rfc1929.go
@@ -39,8 +39,8 @@ func (req *Request) authRFC1929() (err error) {
sendErrResp := func() {
// Swallow write/flush errors, the auth failure is the relevant error.
resp := []byte{authRFC1929Ver, authRFC1929Fail}
- req.rw.Write(resp[:])
- req.flushBuffers()
+ _, _ = req.rw.Write(resp[:])
+ _ = req.flushBuffers()
}
// The client sends a Username/Password request.
diff --git a/common/socks5/socks5.go b/common/socks5/socks5.go
index 74e1175..002ba7b 100644
--- a/common/socks5/socks5.go
+++ b/common/socks5/socks5.go
@@ -111,6 +111,8 @@ func ErrorToReplyCode(err error) ReplyCode {
return ReplyHostUnreachable
case syscall.ECONNREFUSED, syscall.ECONNRESET:
return ReplyConnectionRefused
+ case syscall.EPERM:
+ return ReplyConnectionNotAllowed
default:
return ReplyGeneralFailure
}
@@ -267,15 +269,15 @@ func (req *Request) readCommand() error {
var err error
if err = req.readByteVerify("version", version); err != nil {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return err
}
if err = req.readByteVerify("command", cmdConnect); err != nil {
- req.Reply(ReplyCommandNotSupported)
+ _ = req.Reply(ReplyCommandNotSupported)
return err
}
if err = req.readByteVerify("reserved", rsv); err != nil {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return err
}
@@ -283,49 +285,49 @@ func (req *Request) readCommand() error {
var atyp byte
var host string
if atyp, err = req.readByte(); err != nil {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return err
}
switch atyp {
case atypIPv4:
var addr []byte
if addr, err = req.readBytes(net.IPv4len); err != nil {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return err
}
host = net.IPv4(addr[0], addr[1], addr[2], addr[3]).String()
case atypDomainName:
var alen byte
if alen, err = req.readByte(); err != nil {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return err
}
if alen == 0 {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return fmt.Errorf("domain name with 0 length")
}
var addr []byte
if addr, err = req.readBytes(int(alen)); err != nil {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return err
}
host = string(addr)
case atypIPv6:
var rawAddr []byte
if rawAddr, err = req.readBytes(net.IPv6len); err != nil {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return err
}
addr := make(net.IP, net.IPv6len)
copy(addr[:], rawAddr[:])
host = fmt.Sprintf("[%s]", addr.String())
default:
- req.Reply(ReplyAddressNotSupported)
+ _ = req.Reply(ReplyAddressNotSupported)
return fmt.Errorf("unsupported address type 0x%02x", atyp)
}
var rawPort []byte
if rawPort, err = req.readBytes(2); err != nil {
- req.Reply(ReplyGeneralFailure)
+ _ = req.Reply(ReplyGeneralFailure)
return err
}
port := int(rawPort[0])<<8 | int(rawPort[1])