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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user