Skip to content

Commit f7811ab

Browse files
committed
fix nil pointer panic in v2.5.3' :s5s
1 parent d487141 commit f7811ab

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

apps/nc.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
)
3535

3636
var (
37-
VERSION = "v2.5.3"
37+
VERSION = "v2.5.4"
3838
)
3939

4040
type AppNetcatConfig struct {
@@ -325,16 +325,16 @@ func AppNetcatConfigByArgs(logWriter io.Writer, argv0 string, args []string) (*A
325325
// 1. 初始化基本设置
326326
firstInit(config)
327327

328-
// 2. 配置内置应用程序模式(例如http服务器,socks5)
329-
configureAppMode(config)
330-
331-
// 3. 配置安全功能,如PSK和ACL
328+
// 2. 配置安全功能,如PSK和ACL
332329
err = configureSecurity(config)
333330
if err != nil {
334331
fmt.Fprintf(logWriter, "Security configuration failed: %v\n", err)
335332
os.Exit(1)
336333
}
337334

335+
// 3. 配置内置应用程序模式(例如http服务器,socks5)
336+
configureAppMode(config)
337+
338338
if fs.NFlag() == 0 && fs.NArg() == 0 {
339339
usage_less(logWriter, argv0)
340340
os.Exit(1)
@@ -1982,6 +1982,9 @@ func preinitBuiltinAppConfig(ncconfig *AppNetcatConfig, commandline string) erro
19821982
ncconfig.app_s5s_Config, err = AppS5SConfigByArgs(ncconfig.LogWriter, args[1:])
19831983
if err == nil {
19841984
ncconfig.app_s5s_Config.AccessCtrl = ncconfig.accessControl
1985+
if ncconfig.app_s5s_Config.UpstreamClient != nil && ncconfig.accessControl != nil {
1986+
ncconfig.Logger.Printf(":s5s -x enabled: outbound ACL for target addresses is ignored; inbound ACL still applies.\n")
1987+
}
19851988
}
19861989
case ":s5c":
19871990
ncconfig.app_s5c_Config, err = AppS5CConfigByArgs(ncconfig.LogWriter, args[1:])

apps/proxyclient.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,29 @@ func (c *DirectDialer) Listen(network, address string) (net.Listener, error) {
156156

157157
// Dial 实现 ProxyClient 的拨号逻辑,委托给内部的 dialer
158158
func (c *ProxyClient) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
159+
if c == nil {
160+
return nil, fmt.Errorf("proxy client not initialized")
161+
}
159162
if c.Dialer == nil {
160163
return nil, fmt.Errorf("proxy client not initialized, call NewProxyClient first")
161164
}
162165
return c.Dialer.DialTimeout(network, address, timeout)
163166
}
164167

165168
func (c *ProxyClient) Listen(network, address string) (net.Listener, error) {
169+
if c == nil {
170+
return nil, fmt.Errorf("proxy client not initialized")
171+
}
166172
if c.Dialer == nil {
167173
return nil, fmt.Errorf("proxy client not initialized")
168174
}
169175
return c.Dialer.Listen(network, address)
170176
}
171177

172178
func (c *ProxyClient) SupportBIND() bool {
179+
if c == nil {
180+
return false
181+
}
173182
// 目前仅 SOCKS5 支持 BIND
174183
return c.ProxyProt == "socks5"
175184
}

apps/proxyserver.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func handleSocks5Proxy(conn net.Conn, keyingMaterial [32]byte, config *AppS5SCon
2727
ServerIP: config.ServerIP,
2828
Localbind: config.Localbind,
2929
AccessCtrl: config.AccessCtrl,
30-
Outbound: config.UpstreamClient,
30+
}
31+
if config.UpstreamClient != nil {
32+
s5config.Outbound = config.UpstreamClient
3133
}
3234
s5auth := &Socks5AuthConfig{
3335
AuthenticateUser: nil,

0 commit comments

Comments
 (0)