Reject overflowing manual ban durations

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-10 01:11:58 -04:00
committed by Brandon McGinty
parent 55772fa459
commit e8e2fc46a9
2 changed files with 7 additions and 1 deletions
+4 -1
View File
@@ -896,13 +896,16 @@ func (b *Barnard) addManualBan(text string) {
// manualBanDuration validates user input before it reaches the unsigned
// protocol duration field.
func manualBanDuration(text string) (time.Duration, error) {
minutes, err := strconv.Atoi(text)
minutes, err := strconv.ParseInt(text, 10, 64)
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")
}
if minutes > int64((1<<63-1)/time.Minute) {
return 0, fmt.Errorf("ban duration is too long")
}
return time.Duration(minutes) * time.Minute, nil
}
+3
View File
@@ -85,6 +85,9 @@ func TestManualBanDurationRejectsNegativeMinutes(t *testing.T) {
if _, err := manualBanDuration("-1"); err == nil {
t.Fatal("negative duration was accepted")
}
if _, err := manualBanDuration("9223372036854775807"); err == nil {
t.Fatal("overflowing duration was accepted")
}
got, err := manualBanDuration("15")
if err != nil || got != 15*60*1000000000 {
t.Fatalf("got %v, %v", got, err)