Skip to content

fix: return error instead of panic for TZ= without space#566

Open
Yanhu007 wants to merge 1 commit into
robfig:masterfrom
Yanhu007:fix/tz-no-space-panic
Open

fix: return error instead of panic for TZ= without space#566
Yanhu007 wants to merge 1 commit into
robfig:masterfrom
Yanhu007:fix/tz-no-space-panic

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #554

Problem

cron.ParseStandard("TZ=0") panics with slice bounds out of range because strings.Index(spec, " ") returns -1 when there is no space after the timezone prefix, causing spec[eq+1 : -1] to panic.

This is dangerous in production when user-provided cron expressions are parsed.

Fix

Check if the space index is -1 and return a descriptive error instead of panicking.

Test

_, err := cron.ParseStandard("TZ=0")
// Before: panic: runtime error: slice bounds out of range [3:-1]
// After:  err = "missing time zone specification or fields after TZ="

All existing tests pass.

ParseStandard("TZ=0") panics because strings.Index(spec, " ")
returns -1 when there is no space after the timezone, causing
spec[eq+1 : -1] to panic with a slice bounds out of range error.

Check for i == -1 and return a descriptive error instead.

Fixes robfig#554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cron.ParseStandard("TZ=0") causes panic

1 participant