From 6ef904977f492db1a8fde6cee801ea0eb2da7284 Mon Sep 17 00:00:00 2001 From: devteamaegis Date: Thu, 11 Jun 2026 03:32:54 -0400 Subject: [PATCH] fix(crontab): avoid panic on env line with empty value A crontab env line with an empty value (e.g. "FOO=") matched the env regex with an empty value group, and the quote-stripping check indexed envVal[0] unconditionally, panicking with index out of range on the empty string. Guard the quote check on len(envVal) > 0 so an empty assignment parses to an empty value, matching Vixie cron behavior. --- crontab/crontab.go | 2 +- crontab/crontab_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crontab/crontab.go b/crontab/crontab.go index e55937d..a07eeee 100644 --- a/crontab/crontab.go +++ b/crontab/crontab.go @@ -85,7 +85,7 @@ func ParseCrontab(reader io.Reader) (*Crontab, error) { envVal := r[0][2] // Remove quotes (this emulates what Vixie cron does) - if envVal[0] == '"' || envVal[0] == '\'' { + if len(envVal) > 0 && (envVal[0] == '"' || envVal[0] == '\'') { if len(envVal) > 1 && envVal[0] == envVal[len(envVal)-1] { envVal = envVal[1 : len(envVal)-1] } diff --git a/crontab/crontab_test.go b/crontab/crontab_test.go index 995d7c7..df8a7b0 100644 --- a/crontab/crontab_test.go +++ b/crontab/crontab_test.go @@ -110,6 +110,18 @@ var parseCrontabTestCases = []struct { }, }, + { + "FOO=", + &Crontab{ + Context: &Context{ + Shell: "/bin/sh", + Environ: map[string]string{"FOO": ""}, + Timezone: time.Local, + }, + Jobs: []*Job{}, + }, + }, + { "CRON_TZ=UTC", &Crontab{