diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-04-20 18:08:15 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-04-20 18:08:23 -0400 |
commit | eafdf9de06e9b60168f5e47cedcfceecdc6d4b5f (patch) | |
tree | ed39d40ff06d644ca35f0960cbce55cd398b9e07 /src/backend/utils/adt/timestamp.c | |
parent | d2d35479796c3510e249d6fc72adbd5df918efbf (diff) | |
download | postgresql-eafdf9de06e9b60168f5e47cedcfceecdc6d4b5f.tar.gz postgresql-eafdf9de06e9b60168f5e47cedcfceecdc6d4b5f.zip |
Disallow infinite endpoints in generate_series() for timestamps.
Such cases will lead to infinite loops, so they're of no practical
value. The numeric variant of generate_series() already threw error
for this, so borrow its message wording.
Per report from Richard Wesley. Back-patch to all supported branches.
Discussion: https://postgr.es/m/91B44E7B-68D5-448F-95C8-B4B3B0F5DEAF@duckdblabs.com
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 552b631ba78..93c10e1ae41 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -5778,6 +5778,20 @@ generate_series_timestamp(PG_FUNCTION_ARGS) MemoryContext oldcontext; Interval interval_zero; + /* Reject infinities in start and stop values */ + if (TIMESTAMP_IS_NOBEGIN(start) || + TIMESTAMP_IS_NOEND(start)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("start value cannot be infinity"))); + if (TIMESTAMP_IS_NOBEGIN(finish) || + TIMESTAMP_IS_NOEND(finish)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("stop value cannot be infinity"))); + + /* Interval doesn't (currently) have infinity, so nothing to check */ + /* create a function context for cross-call persistence */ funcctx = SRF_FIRSTCALL_INIT(); @@ -5858,6 +5872,20 @@ generate_series_timestamptz(PG_FUNCTION_ARGS) MemoryContext oldcontext; Interval interval_zero; + /* Reject infinities in start and stop values */ + if (TIMESTAMP_IS_NOBEGIN(start) || + TIMESTAMP_IS_NOEND(start)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("start value cannot be infinity"))); + if (TIMESTAMP_IS_NOBEGIN(finish) || + TIMESTAMP_IS_NOEND(finish)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("stop value cannot be infinity"))); + + /* Interval doesn't (currently) have infinity, so nothing to check */ + /* create a function context for cross-call persistence */ funcctx = SRF_FIRSTCALL_INIT(); |