fix(parser): return error instead of panicking on TZ= prefix with no schedule#567
Open
SAY-5 wants to merge 1 commit intorobfig:masterfrom
Open
fix(parser): return error instead of panicking on TZ= prefix with no schedule#567SAY-5 wants to merge 1 commit intorobfig:masterfrom
SAY-5 wants to merge 1 commit intorobfig:masterfrom
Conversation
…schedule Parser.Parse supports an optional 'TZ=...' or 'CRON_TZ=...' prefix terminated by the first space character, with the schedule expression following. If the prefix is provided alone (e.g. 'TZ=0' with no space) the space-index lookup returned -1, and spec[eq+1:-1] sliced a negative upper bound, panicking with 'slice bounds out of range [:-1]' on fuzz-style input (robfig#554). Detect the missing space explicitly and return a normal parse error ('missing schedule after timezone prefix: %q') so callers that treat their input as untrusted (cron expressions from users, config files, automated fuzzers) see a regular error return instead of a runtime panic crashing the process. Added regression coverage in TestParseScheduleErrors for three representative inputs: 'TZ=0', 'TZ=UTC', and 'CRON_TZ=America/Los_Angeles'. Closes robfig#554 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #554.
Parser.Parsesupports an optionalTZ=.../CRON_TZ=...prefix terminated by the first space character. If the prefix is provided alone (e.g.TZ=0with no space), the space-index lookup returns-1andspec[eq+1:-1]slices a negative upper bound, panicking at runtime withslice bounds out of range [:-1].This is easy to hit in production scenarios where cron expressions come from user input or fuzz testing: any user that enters just a timezone prefix without a schedule crashes the host process.
Fix
Detect the missing space explicitly and return a normal parse error (
missing schedule after timezone prefix: %q) so untrusted-input callers see a regular error return instead of a runtime panic.Tests
Added three rows to
TestParseScheduleErrors-TZ=0,TZ=UTC, andCRON_TZ=America/Los_Angeles- each asserting the new error message. All three trip the panic on master and pass after the fix.Verification
Locally on macOS, go 1.26.2:
gofmt -s -l: cleango vet ./...: cleango test -race -count=1 ./...: passCloses #554