From 64a68c73807f8bbbc3176847fe5cfa896e7bc976 Mon Sep 17 00:00:00 2001 From: kevin9327 <5299031+kevin9327@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:16:16 +0900 Subject: [PATCH] fs: reject --bwlimit times without a colon or with signed digits validateHour only checked the length of the hh:mm field and then parsed the two halves with strconv.Atoi. It never checked the third character, so "10h20" or "Mon-10.20" were accepted as 10:20, and since Atoi accepts a sign, "+1:00" and "Mon-10:+5" were accepted as 01:00 and 10:05. Require the colon and four digits so these are reported as invalid time specifications like other malformed times. --- fs/bwtimetable.go | 8 +++++++- fs/bwtimetable_test.go | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/bwtimetable.go b/fs/bwtimetable.go index b5006e623..763417882 100644 --- a/fs/bwtimetable.go +++ b/fs/bwtimetable.go @@ -82,9 +82,15 @@ func (x BwTimetable) String() string { // Basic hour format checking func validateHour(HHMM string) error { - if len(HHMM) != 5 { + if len(HHMM) != 5 || HHMM[2] != ':' { return fmt.Errorf("invalid time specification (hh:mm): %q", HHMM) } + // strconv.Atoi accepts a sign, so check for digits explicitly + for _, i := range []int{0, 1, 3, 4} { + if HHMM[i] < '0' || HHMM[i] > '9' { + return fmt.Errorf("invalid time specification (hh:mm): %q", HHMM) + } + } hh, err := strconv.Atoi(HHMM[0:2]) if err != nil { return fmt.Errorf("invalid hour in time specification %q: %v", HHMM, err) diff --git a/fs/bwtimetable_test.go b/fs/bwtimetable_test.go index 0692d2c92..dc76d532c 100644 --- a/fs/bwtimetable_test.go +++ b/fs/bwtimetable_test.go @@ -32,6 +32,10 @@ func TestBwTimetableSet(t *testing.T) { {"bad-10:20,666", BwTimetable{}, true, ""}, {"Mon-bad,666", BwTimetable{}, true, ""}, {"Mon-10:20,bad", BwTimetable{}, true, ""}, + {"10h20,666", BwTimetable{}, true, ""}, + {"Mon-10.20,666", BwTimetable{}, true, ""}, + {"+1:00,666", BwTimetable{}, true, ""}, + {"Mon-10:+5,666", BwTimetable{}, true, ""}, { "0", BwTimetable{