Skip to content

Commit

Permalink
fix error of too short request, which lead to crash of server side
Browse files Browse the repository at this point in the history
  • Loading branch information
asche910 committed Oct 18, 2019
1 parent 9b2fa40 commit f2ba858
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion fly/pac.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func StartPAC() {
if err != nil {
fmt.Println(err)
// run from cmd/client/
file, _ = os.Open("../../flynet.pac")
file, _ = os.Open("../flynet.pac")
//file, _ = os.Open("../../flynet.pac")
}
w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig")
io.Copy(w, file)
Expand Down
2 changes: 1 addition & 1 deletion fly/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func RelayTraffic(dst, src net.Conn) {
n, err := src.Read(buff)
if err != nil {
if err != io.EOF {
fmt.Println(err)
logger.Println(err)
}
break
}
Expand Down
22 changes: 16 additions & 6 deletions fly/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fly

import (
"crypto/sha1"
"fmt"
"github.com/xtaci/kcp-go"
"golang.org/x/crypto/pbkdf2"
"io"
Expand Down Expand Up @@ -42,7 +43,10 @@ func handleClient(client net.Conn) {
// read the detail request from client
n, err = client.Read(data[:])
if err != nil {
logger.Println("read from client failed!")
logger.Println("read from client failed --->", err)
return
} else if n < 7 {
logger.Println("read error of request length --->", data[:n])
return
}

Expand Down Expand Up @@ -136,6 +140,9 @@ func Socks5ForServerByTCP(localPort, method, key string) {
if err != nil {
logger.Println("read target address failed --->", err)
return
}else if n < 7 {
logger.Println("read error of request length --->", buff[:n])
return
}

host, port := parseSocksRequest(buff[:n], n)
Expand All @@ -159,16 +166,16 @@ func Socks5ForClientByUDP(localPort, serverAddr string) {
for {
con, err := listener.Accept()
if err != nil {
logger.Println("accept error: ", err)
logger.Println("accept error --->", err)
continue
}
logger.Println("client accepted!")
logger.Println("client accepted.")

go func() {
var b [1024] byte
_, err := con.Read(b[:])
if err != nil {
logger.Println("read error!")
logger.Println("read error --->", err)
return
}
if b[0] == 0x05 {
Expand All @@ -183,7 +190,7 @@ func Socks5ForClientByUDP(localPort, serverAddr string) {
block, _ := kcp.NewAESBlockCrypt(key)
session, err := kcp.DialWithOptions(serverAddr, block, 10, 3)
if err != nil {
logger.Println("connect targetServer failed! ", err)
logger.Println("connect targetServer failed --->", err)
return
}
go TCPToUDP(session, con)
Expand All @@ -207,7 +214,10 @@ func Socks5ForServerByUDP(localPort string) {
data := make([]byte, 1024)
n, err := con.Read(data)
if err != nil {
logger.Println(err)
logger.Println("read target address failed --->", err)
return
}else if n < 7 {
logger.Println("read error of request length --->", data[:n])
return
}
//logger.Println(string(data[:n]))
Expand Down

0 comments on commit f2ba858

Please sign in to comment.