fix(ss): address review findings for PR #96 — nil guards, resource leaks, dead code
- Bump go-shadowsocks2 to v0.1.3 (new API symbols) - Return error instead of nil when Target() is empty in TCP handler - Reset wbuf unconditionally on write error to prevent unbounded growth - Add nil guard on targetAddr before WriteTo to prevent panic - Remove duplicate NewClientConfig call and dead ClientConfig literal - Remove unused noDelay metadata field - Fix buffer-size guard to catch negative values (len(b)==0 → bufSize<=0) - Add address context to parse/session error messages
This commit is contained in:
@@ -10,19 +10,16 @@ import (
|
||||
type metadata struct {
|
||||
key string
|
||||
connectTimeout time.Duration
|
||||
noDelay bool
|
||||
}
|
||||
|
||||
func (c *ssConnector) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
key = "key"
|
||||
connectTimeout = "timeout"
|
||||
noDelay = "nodelay"
|
||||
)
|
||||
|
||||
c.md.key = mdutil.GetString(md, key)
|
||||
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
|
||||
c.md.noDelay = mdutil.GetBool(md, noDelay)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -58,13 +58,8 @@ func (c *ssuConnector) Init(md md.Metadata) (err error) {
|
||||
}
|
||||
clientConfig.UDPTimeout = time.Minute
|
||||
|
||||
tcpClientConfig, err := utils.NewClientConfig(method, password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.clientCfg = clientConfig
|
||||
c.tcpClient = core.NewTCPClient(tcpClientConfig)
|
||||
c.tcpClient = core.NewTCPClient(clientConfig)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -98,15 +93,11 @@ func (c *ssuConnector) Connect(ctx context.Context, conn net.Conn, network, addr
|
||||
}
|
||||
serverAddr, err := netip.ParseAddrPort(conn.RemoteAddr().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("ss: parse remote addr %q: %w", conn.RemoteAddr().String(), err)
|
||||
}
|
||||
clientCfg := c.clientCfg
|
||||
clientCfg.ServerAddr = serverAddr
|
||||
client := core.NewUDPClient(core.ClientConfig{
|
||||
Cipher: clientCfg.Cipher,
|
||||
ServerAddr: serverAddr,
|
||||
UDPTimeout: time.Minute,
|
||||
})
|
||||
client := core.NewUDPClient(clientCfg)
|
||||
if err := client.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user