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{