fix: reject invalid IRC server ports

This commit is contained in:
rissrice2105-agent 2026-07-18 00:58:18 -06:00
parent 7cb2aba24e
commit e640a67f15
2 changed files with 30 additions and 0 deletions

View file

@ -1856,6 +1856,10 @@ func validIRCServer(s string) bool {
return false return false
} }
} }
portNum, err := strconv.Atoi(port)
if err != nil || portNum < 1 || portNum > 65535 {
return false
}
} }
if host == "" || len(host) > 255 { if host == "" || len(host) > 255 {
return false return false

26
cmd/agentbbs/main_test.go Normal file
View file

@ -0,0 +1,26 @@
package main
import "testing"
func TestValidIRCServerPortRange(t *testing.T) {
for _, server := range []string{
"irc.example.com",
"irc.example.com:1",
"irc.example.com:6667",
"irc.example.com:65535",
} {
if !validIRCServer(server) {
t.Errorf("validIRCServer(%q) = false, want true", server)
}
}
for _, server := range []string{
"irc.example.com:0",
"irc.example.com:65536",
"irc.example.com:99999",
} {
if validIRCServer(server) {
t.Errorf("validIRCServer(%q) = true, want false", server)
}
}
}