mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-08-13 14:27:27 +00:00
fix: reject invalid IRC server ports
This commit is contained in:
parent
7cb2aba24e
commit
e640a67f15
2 changed files with 30 additions and 0 deletions
|
|
@ -1856,6 +1856,10 @@ func validIRCServer(s string) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
portNum, err := strconv.Atoi(port)
|
||||
if err != nil || portNum < 1 || portNum > 65535 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if host == "" || len(host) > 255 {
|
||||
return false
|
||||
|
|
|
|||
26
cmd/agentbbs/main_test.go
Normal file
26
cmd/agentbbs/main_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue