fix: update port validation logic for Socks5 and MTProto configurations

This commit is contained in:
Daniel Lavrushin 2026-05-09 13:14:49 +02:00
parent 016c950e2b
commit d1020ce38b
No known key found for this signature in database
GPG key ID: 57F1CAB57AD35056
2 changed files with 10 additions and 2 deletions

View file

@ -264,14 +264,14 @@ func (c *Config) checkPortCollisions(v *validator) {
if c.System.WebServer.Port > 0 && c.System.WebServer.Port <= 65535 {
refs = append(refs, portRef{"system.web_server.port", c.System.WebServer.Port})
}
if c.System.Socks5.Enabled && c.System.Socks5.Port > 0 {
if c.System.Socks5.Enabled {
if c.System.Socks5.Port < 1 || c.System.Socks5.Port > 65535 {
v.add("system.socks5.port", "out_of_range", "port must be between 1 and 65535", portRangeParams)
} else {
refs = append(refs, portRef{"system.socks5.port", c.System.Socks5.Port})
}
}
if c.System.MTProto.Enabled && c.System.MTProto.Port > 0 {
if c.System.MTProto.Enabled {
if c.System.MTProto.Port < 1 || c.System.MTProto.Port > 65535 {
v.add("system.mtproto.port", "out_of_range", "port must be between 1 and 65535", portRangeParams)
} else {

View file

@ -98,6 +98,14 @@ func TestValidate_PortOutOfRange(t *testing.T) {
c.System.Socks5.Enabled = true
c.System.Socks5.Port = 70000
}, "system.socks5.port"},
{"mtproto enabled with port 0", func(c *Config) {
c.System.MTProto.Enabled = true
c.System.MTProto.Port = 0
}, "system.mtproto.port"},
{"socks5 enabled with port 0", func(c *Config) {
c.System.Socks5.Enabled = true
c.System.Socks5.Port = 0
}, "system.socks5.port"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {