Skip to content

Commit

Permalink
Fix segfault in alter_job
Browse files Browse the repository at this point in the history
When trying to alter a job with NULL config alter_job did not
set the isnull field for config and would segfault when trying
to build the resultset tuple.
  • Loading branch information
svenklemm committed Aug 21, 2020
1 parent aec7c59 commit c281dcd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tsl/src/bgw_policy/job_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ job_alter(PG_FUNCTION_ARGS)
values[3] = Int32GetDatum(job->fd.max_retries);
values[4] = IntervalPGetDatum(&job->fd.retry_period);
values[5] = BoolGetDatum(job->fd.scheduled);
values[6] = JsonbPGetDatum(job->fd.config);

if (job->fd.config == NULL)
nulls[6] = true;
else
values[6] = JsonbPGetDatum(job->fd.config);

values[7] = TimestampTzGetDatum(next_start);

tuple = heap_form_tuple(tupdesc, values, nulls);
Expand Down
8 changes: 8 additions & 0 deletions tsl/test/expected/bgw_custom.out
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,11 @@ SELECT * FROM _timescaledb_config.bgw_job WHERE id >= 1000;
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)

\c :TEST_DBNAME :ROLE_SUPERUSER
-- test altering job with NULL config
SELECT job_id FROM alter_job(1,scheduled:=false);
job_id
--------
1
(1 row)

4 changes: 4 additions & 0 deletions tsl/test/sql/bgw_custom.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ SELECT delete_job(1004);
-- check jobs got removed
SELECT * FROM _timescaledb_config.bgw_job WHERE id >= 1000;

\c :TEST_DBNAME :ROLE_SUPERUSER
-- test altering job with NULL config
SELECT job_id FROM alter_job(1,scheduled:=false);

0 comments on commit c281dcd

Please sign in to comment.