Skip to content

Commit

Permalink
Add checks for NULL arguments to DDL functions
Browse files Browse the repository at this point in the history
Add checks for NULL arguments to ts_chunk_adaptive_set,
ts_dimension_set_num_slices, ts_dimension_set_interval,
ts_dimension_add and ts_hypertable_create
  • Loading branch information
svenklemm authored and RobAtticus committed Dec 4, 2018
1 parent b6ae78b commit 2e7cc4b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/chunk_adaptive.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ ts_chunk_adaptive_set(PG_FUNCTION_ARGS)
Datum values[2];
bool nulls[2] = {false, false};

if (PG_ARGISNULL(0))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid hypertable: cannot be NULL")));

if (!OidIsValid(info.table_relid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
Expand Down
26 changes: 26 additions & 0 deletions src/dimension.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,11 @@ ts_dimension_set_num_slices(PG_FUNCTION_ARGS)
Name colname = PG_ARGISNULL(2) ? NULL : PG_GETARG_NAME(2);
int16 num_slices;

if (PG_ARGISNULL(0))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid main_table: cannot be NULL")));

hypertable_permissions_check(table_relid, GetUserId());

if (PG_ARGISNULL(1) || !IS_VALID_NUM_SLICES(num_slices_arg))
Expand All @@ -880,13 +885,29 @@ ts_dimension_set_num_slices(PG_FUNCTION_ARGS)

TS_FUNCTION_INFO_V1(ts_dimension_set_interval);

/*
* Update chunk_time_interval for a hypertable.
*
* main_table - The OID of the table corresponding to a hypertable whose time
* interval should be updated
* chunk_time_interval - The new time interval. For hypertables with integral
* time columns, this must be an integral type. For hypertables with a
* TIMESTAMP/TIMESTAMPTZ/DATE type, it can be integral which is treated as
* microseconds, or an INTERVAL type.
* dimension_name - The name of the dimension
*/
Datum
ts_dimension_set_interval(PG_FUNCTION_ARGS)
{
Oid table_relid = PG_GETARG_OID(0);
Datum interval = PG_GETARG_DATUM(1);
Name colname = PG_ARGISNULL(2) ? NULL : PG_GETARG_NAME(2);

if (PG_ARGISNULL(0))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid main_table: cannot be NULL")));

hypertable_permissions_check(table_relid, GetUserId());

if (PG_ARGISNULL(1))
Expand Down Expand Up @@ -1066,6 +1087,11 @@ ts_dimension_add(PG_FUNCTION_ARGS)
};
Datum retval = 0;

if (PG_ARGISNULL(0))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid main_table: cannot be NULL")));

hypertable_permissions_check(info.table_relid, GetUserId());

/*
Expand Down
10 changes: 10 additions & 0 deletions src/hypertable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,16 @@ ts_hypertable_create(PG_FUNCTION_ARGS)
Relation rel;
Datum retval;

if (PG_ARGISNULL(0))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid main_table: cannot be NULL")));

if (PG_ARGISNULL(1))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid time_column_name: cannot be NULL")));

/* quick exit in the easy if-not-exists case to avoid all locking */
if (if_not_exists && is_hypertable(table_relid))
{
Expand Down

0 comments on commit 2e7cc4b

Please sign in to comment.