From 1679a37783327cef23fcfd9f0ce579791ca03077 Mon Sep 17 00:00:00 2001 From: "Brandon McGinty (chatgpt)" Date: Sun, 9 Aug 2026 14:55:39 -0400 Subject: [PATCH] Clamp negative protocol ban durations --- gumble/gumble/bans.go | 6 ++++++ gumble/gumble/bans_regression_test.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 gumble/gumble/bans_regression_test.go diff --git a/gumble/gumble/bans.go b/gumble/gumble/bans.go index 01427f6..01eaa3c 100644 --- a/gumble/gumble/bans.go +++ b/gumble/gumble/bans.go @@ -16,6 +16,9 @@ type BanList []*Ban // Add creates a new ban list entry with the given parameters. func (b *BanList) Add(address net.IP, mask net.IPMask, reason string, duration time.Duration) *Ban { + if duration < 0 { + duration = 0 + } ban := &Ban{ Address: address, Mask: mask, @@ -66,6 +69,9 @@ func (b *Ban) SetReason(reason string) { // SetDuration changes the duration of the ban. func (b *Ban) SetDuration(duration time.Duration) { + if duration < 0 { + duration = 0 + } b.Duration = duration } diff --git a/gumble/gumble/bans_regression_test.go b/gumble/gumble/bans_regression_test.go new file mode 100644 index 0000000..6ba90aa --- /dev/null +++ b/gumble/gumble/bans_regression_test.go @@ -0,0 +1,21 @@ +package gumble + +import ( + "net" + "testing" + "time" +) + +// Regression: negative durations were converted to uint32 seconds for the +// protocol, creating an unexpectedly huge ban rather than a safe duration. +func TestBanDurationsNeverRemainNegative(t *testing.T) { + var bans BanList + ban := bans.Add(net.ParseIP("192.0.2.1"), net.CIDRMask(32, 32), "test", -time.Minute) + if ban.Duration != 0 { + t.Fatalf("Add duration = %v", ban.Duration) + } + ban.SetDuration(-time.Second) + if ban.Duration != 0 { + t.Fatalf("SetDuration = %v", ban.Duration) + } +}