From d9633e5c4e78a3c68886bf44de39542282e8f31b Mon Sep 17 00:00:00 2001 From: Tristan Pemble Date: Tue, 19 Jul 2022 08:21:06 -0700 Subject: [PATCH 1/2] fix(#13844): canonicalize job to avoid nil pointer deference --- command/job_run.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/command/job_run.go b/command/job_run.go index 7e7090f1646c..46e9699f9666 100644 --- a/command/job_run.go +++ b/command/job_run.go @@ -349,6 +349,9 @@ func (c *JobRunCommand) Run(args []string) int { evalID := resp.EvalID + // #13844: canonicalize the job in case it was a partial API definition + job.Canonicalize() + // Check if we should enter monitor mode if detach || periodic || paramjob || multiregion { c.Ui.Output("Job registration successful") From 9a7c60e862050df59730332969b3e818a39d15c1 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Wed, 1 Feb 2023 14:53:40 -0500 Subject: [PATCH 2/2] fix nil deference for all API callers --- .changelog/13845.txt | 3 +++ api/jobs.go | 2 +- command/job_run.go | 3 --- 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 .changelog/13845.txt diff --git a/.changelog/13845.txt b/.changelog/13845.txt new file mode 100644 index 000000000000..88778bcc8f40 --- /dev/null +++ b/.changelog/13845.txt @@ -0,0 +1,3 @@ +```release-note:bug +api: Fixed a nil pointer dereference when periodic jobs are missing their periodic spec +``` diff --git a/api/jobs.go b/api/jobs.go index a9011189731d..c9921c9fd3bf 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -822,7 +822,7 @@ func (p *PeriodicConfig) Canonicalize() { // returned. The `time.Location` of the returned value matches that of the // passed time. func (p *PeriodicConfig) Next(fromTime time.Time) (time.Time, error) { - if *p.SpecType == PeriodicSpecCron { + if p != nil && *p.SpecType == PeriodicSpecCron { e, err := cronexpr.Parse(*p.Spec) if err != nil { return time.Time{}, fmt.Errorf("failed parsing cron expression %q: %v", *p.Spec, err) diff --git a/command/job_run.go b/command/job_run.go index 46e9699f9666..7e7090f1646c 100644 --- a/command/job_run.go +++ b/command/job_run.go @@ -349,9 +349,6 @@ func (c *JobRunCommand) Run(args []string) int { evalID := resp.EvalID - // #13844: canonicalize the job in case it was a partial API definition - job.Canonicalize() - // Check if we should enter monitor mode if detach || periodic || paramjob || multiregion { c.Ui.Output("Job registration successful")