Skip to content

Commit 2d0ff8e

Browse files
committed
Guard time bucket parameter handling against bad input
Reading the time bucket parameters of a continuous aggregate could read from a NULL pointer when the timezone or offset argument was a NULL constant, and could read past the end of the argument list when the function had fewer than two arguments. Skip the read when the constant is NULL, and check the number of arguments before accessing them.
1 parent 44f54bd commit 2d0ff8e

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

.unreleased/pr_9708

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #9708 Guard time bucket parameter handling against bad input

tsl/src/continuous_aggs/common.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,25 @@ process_additional_timebucket_parameter(ContinuousAggBucketFunction *bf, Const *
188188
{
189189
/* Timezone as text */
190190
case TEXTOID:
191-
tz_name = TextDatumGetCString(arg->constvalue);
192-
if (!ts_is_valid_timezone_name(tz_name))
191+
if (!arg->constisnull)
193192
{
194-
ereport(ERROR,
195-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
196-
errmsg("invalid timezone name \"%s\"", tz_name)));
197-
}
193+
tz_name = TextDatumGetCString(arg->constvalue);
194+
if (!ts_is_valid_timezone_name(tz_name))
195+
{
196+
ereport(ERROR,
197+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
198+
errmsg("invalid timezone name \"%s\"", tz_name)));
199+
}
198200

199-
bf->bucket_time_timezone = tz_name;
201+
bf->bucket_time_timezone = tz_name;
202+
}
200203
break;
201204
case INTERVALOID:
202205
/* Bucket offset as interval */
203-
bf->bucket_time_offset = DatumGetIntervalP(arg->constvalue);
206+
if (!arg->constisnull)
207+
{
208+
bf->bucket_time_offset = DatumGetIntervalP(arg->constvalue);
209+
}
204210
break;
205211
case DATEOID:
206212
/* Bucket origin as Date */
@@ -258,6 +264,14 @@ process_timebucket_parameters(FuncExpr *fe, ContinuousAggBucketFunction *bf, boo
258264
TIMESTAMP_NOBEGIN(bf->bucket_time_origin);
259265
int nargs;
260266

267+
nargs = list_length(fe->args);
268+
if (nargs < 2 || nargs > 5)
269+
{
270+
ereport(ERROR,
271+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
272+
errmsg("unsupported time bucket function signature")));
273+
}
274+
261275
/* Only column allowed : time_bucket('1day', <column> ) */
262276
col_arg = lsecond(fe->args);
263277

@@ -286,9 +300,6 @@ process_timebucket_parameters(FuncExpr *fe, ContinuousAggBucketFunction *bf, boo
286300
return;
287301
}
288302

289-
nargs = list_length(fe->args);
290-
Assert(nargs >= 2 && nargs <= 5);
291-
292303
/*
293304
* Process the third argument of the time bucket function. This could be `timezone`, `offset`,
294305
* or `origin`.

0 commit comments

Comments
 (0)