aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/datetime.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-02-12 12:50:55 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-02-12 12:50:55 -0500
commit0ef65d0f55e5cec81fe98aba7c907dfc1b93923f (patch)
tree34da4fb9ca142a2377724cf194e1c286c6dcf6aa /src/backend/utils/adt/datetime.c
parentecb01e6ebb5a67f3fc00840695682a8b1ba40461 (diff)
downloadpostgresql-0ef65d0f55e5cec81fe98aba7c907dfc1b93923f.tar.gz
postgresql-0ef65d0f55e5cec81fe98aba7c907dfc1b93923f.zip
Avoid dereferencing an undefined pointer in DecodeInterval().
Commit e39f99046 moved some code up closer to the start of DecodeInterval(), without noticing that it had been implicitly relying on previous checks to reject the case of empty input. Given empty input, we'd now dereference a pointer that hadn't been set, possibly leading to a core dump. (But if we fail to provoke a SIGSEGV, nothing bad happens, and the expected syntax error is thrown a bit later.) Per bug #17788 from Alexander Lakhin. Back-patch to v15 where the fault was introduced. Discussion: https://postgr.es/m/17788-dabac9f98f7eafd5@postgresql.org
Diffstat (limited to 'src/backend/utils/adt/datetime.c')
-rw-r--r--src/backend/utils/adt/datetime.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index a3cfd54409b..cebc1172744 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -3365,7 +3365,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
* to dump in postgres style, not SQL style.)
*----------
*/
- if (IntervalStyle == INTSTYLE_SQL_STANDARD && *field[0] == '-')
+ if (IntervalStyle == INTSTYLE_SQL_STANDARD && nf > 0 && *field[0] == '-')
{
force_negative = true;
/* Check for additional explicit signs */