Reject negative manual ban durations
This commit is contained in:
committed by
Brandon McGinty
parent
0e9e495a8f
commit
51d62c3acb
@@ -880,17 +880,30 @@ func (b *Barnard) addManualBan(text string) {
|
||||
b.AddOutputLine("Admin: ban address must be CIDR, for example 192.0.2.1/32")
|
||||
return
|
||||
}
|
||||
minutes, err := strconv.Atoi(parts[1])
|
||||
duration, err := manualBanDuration(parts[1])
|
||||
if err != nil {
|
||||
b.AddOutputLine("Admin: ban minutes must be a number")
|
||||
b.AddOutputLine("Admin: " + err.Error())
|
||||
return
|
||||
}
|
||||
reason := strings.Join(parts[2:], " ")
|
||||
b.adminBanList.Add(ip, network.Mask, reason, time.Duration(minutes)*time.Minute)
|
||||
b.adminBanList.Add(ip, network.Mask, reason, duration)
|
||||
b.Client.Send(b.adminBanList)
|
||||
b.AddOutputLine("Admin: manual ban sent")
|
||||
}
|
||||
|
||||
// manualBanDuration validates user input before it reaches the unsigned
|
||||
// protocol duration field.
|
||||
func manualBanDuration(text string) (time.Duration, error) {
|
||||
minutes, err := strconv.Atoi(text)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ban minutes must be a number")
|
||||
}
|
||||
if minutes < 0 {
|
||||
return 0, fmt.Errorf("ban minutes must not be negative")
|
||||
}
|
||||
return time.Duration(minutes) * time.Minute, nil
|
||||
}
|
||||
|
||||
func (b *Barnard) unbanIndex(index int) {
|
||||
if index < 0 || index >= len(b.adminBanList) {
|
||||
b.AddOutputLine("Admin: ban index out of range")
|
||||
|
||||
Reference in New Issue
Block a user