fix panic when using socks5 plugin with encryption and compression, fix #446

This commit is contained in:
fatedier 2018-01-18 00:45:11 +08:00
parent 5b08201e5d
commit 338d5bae37
5 changed files with 10 additions and 19 deletions

View File

@ -426,7 +426,7 @@ func HandleTcpWorkConnection(localInfo *config.LocalSvrConf, proxyPlugin plugin.
if proxyPlugin != nil { if proxyPlugin != nil {
// if plugin is set, let plugin handle connections first // if plugin is set, let plugin handle connections first
workConn.Debug("handle by plugin: %s", proxyPlugin.Name()) workConn.Debug("handle by plugin: %s", proxyPlugin.Name())
proxyPlugin.Handle(remote) proxyPlugin.Handle(remote, workConn)
workConn.Debug("handle by plugin finished") workConn.Debug("handle by plugin finished")
return return
} else { } else {

View File

@ -106,13 +106,8 @@ func (hp *HttpProxy) Name() string {
return PluginHttpProxy return PluginHttpProxy
} }
func (hp *HttpProxy) Handle(conn io.ReadWriteCloser) { func (hp *HttpProxy) Handle(conn io.ReadWriteCloser, realConn frpNet.Conn) {
var wrapConn frpNet.Conn wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn)
if realConn, ok := conn.(frpNet.Conn); ok {
wrapConn = realConn
} else {
wrapConn = frpNet.WrapReadWriteCloserToConn(conn, realConn)
}
sc, rd := frpNet.NewShareConn(wrapConn) sc, rd := frpNet.NewShareConn(wrapConn)
request, err := http.ReadRequest(bufio.NewReader(rd)) request, err := http.ReadRequest(bufio.NewReader(rd))

View File

@ -17,6 +17,8 @@ package plugin
import ( import (
"fmt" "fmt"
"io" "io"
frpNet "github.com/fatedier/frp/utils/net"
) )
// Creators is used for create plugins to handle connections. // Creators is used for create plugins to handle connections.
@ -40,6 +42,6 @@ func Create(name string, params map[string]string) (p Plugin, err error) {
type Plugin interface { type Plugin interface {
Name() string Name() string
Handle(conn io.ReadWriteCloser) Handle(conn io.ReadWriteCloser, realConn frpNet.Conn)
Close() error Close() error
} }

View File

@ -43,16 +43,9 @@ func NewSocks5Plugin(params map[string]string) (p Plugin, err error) {
return return
} }
func (sp *Socks5Plugin) Handle(conn io.ReadWriteCloser) { func (sp *Socks5Plugin) Handle(conn io.ReadWriteCloser, realConn frpNet.Conn) {
defer conn.Close() defer conn.Close()
wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn)
var wrapConn frpNet.Conn
if realConn, ok := conn.(frpNet.Conn); ok {
wrapConn = realConn
} else {
wrapConn = frpNet.WrapReadWriteCloserToConn(conn, realConn)
}
sp.Server.ServeConn(wrapConn) sp.Server.ServeConn(wrapConn)
} }

View File

@ -20,6 +20,7 @@ import (
"net" "net"
frpIo "github.com/fatedier/frp/utils/io" frpIo "github.com/fatedier/frp/utils/io"
frpNet "github.com/fatedier/frp/utils/net"
) )
const PluginUnixDomainSocket = "unix_domain_socket" const PluginUnixDomainSocket = "unix_domain_socket"
@ -51,7 +52,7 @@ func NewUnixDomainSocketPlugin(params map[string]string) (p Plugin, err error) {
return return
} }
func (uds *UnixDomainSocketPlugin) Handle(conn io.ReadWriteCloser) { func (uds *UnixDomainSocketPlugin) Handle(conn io.ReadWriteCloser, realConn frpNet.Conn) {
localConn, err := net.DialUnix("unix", nil, uds.UnixAddr) localConn, err := net.DialUnix("unix", nil, uds.UnixAddr)
if err != nil { if err != nil {
return return