fix: reject invalid IRC server ports (#98)
Some checks failed
CI / build (push) Has been cancelled
deploy / deploy (push) Has been cancelled
test / test (push) Has been cancelled

Co-authored-by: rissrice2105-agent <rissrice2105-agent@users.noreply.github.com>
This commit is contained in:
RissRIce 2026-07-23 20:33:43 -06:00 committed by GitHub
parent 158ea7b718
commit 447b34b895
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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)
}
}
}