pgsql: Catch overflow when rounding intervals in AdjustIntervalForTypmo

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Catch overflow when rounding intervals in AdjustIntervalForTypmo
Date: 2024-02-13 20:58:47
Message-ID: E1rZzrb-0063ow-Nj@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Catch overflow when rounding intervals in AdjustIntervalForTypmod.

Previously, an interval microseconds field close to INT64_MAX or
INT64_MIN could overflow, producing a result with not even the
correct sign, while being rounded to match a precision specification.

This seems worth fixing, but not worth back-patching, in part
because the ereturn() notation doesn't exist very far back.

Report and patch by Joseph Koshakow (some cosmetic mods by me)

Discussion: https://postgr.es/m/CAAvxfHfpuLgqJYzkUcher466Z1LpmE+5Sm+zc8L6zKCOQ+6TDQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5ebc9c90173f32cffe373a80835f157b9ebfa3bd

Modified Files
--------------
src/backend/utils/adt/timestamp.c | 22 ++++++++++++++--------
src/test/regress/expected/interval.out | 8 ++++++++
src/test/regress/sql/interval.sql | 2 ++
3 files changed, 24 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2024-02-13 22:21:24 pgsql: Improve comment about query_id_enabled in queryjumblefuncs.c
Previous Message Heikki Linnakangas 2024-02-13 19:39:49 pgsql: Fix 'mmap' DSM implementation with allocations larger than 4 GB