Reject overflowing manual ban durations
This commit is contained in:
committed by
Brandon McGinty
parent
55772fa459
commit
e8e2fc46a9
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user