pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Guard against overflow in interval_mul() and interval_div().
Date: Sat, 18 Nov 2023 14:52:45 +0000
Message-ID: <E1r4Mgf-0063yV-0O@gemulon.postgresql.org> (raw)

Guard against overflow in interval_mul() and interval_div().

Commits 146604ec43 and a898b409f6 added overflow checks to
interval_mul(), but not to interval_div(), which contains almost
identical code, and so is susceptible to the same kinds of
overflows. In addition, those checks did not catch all possible
overflow conditions.

Add additional checks to the "cascade down" code in interval_mul(),
and copy all the overflow checks over to the corresponding code in
interval_div(), so that they both generate "interval out of range"
errors, rather than returning bogus results.

Given that these errors are relatively easy to hit, back-patch to all
supported branches.

Per bug #18200 from Alexander Lakhin, and subsequent investigation.

Discussion: https://postgr.es/m/18200-5ea288c7b2d504b1%40postgresql.org

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/72d0c135bd7a9ab4602ea1bece0054bb1e8d372d

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



view thread (6+ messages)  latest in thread

Message-ID: <E1r4Mgf-0063yV-0O@gemulon.postgresql.org>
Permalink:  ../E1r4Mgf-0063yV-0O@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1r4Mgf-0063yV-0O@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: dean.a.rasheed@gmail.com, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Guard against overflow in interval_mul() and interval_div().
  In-Reply-To: <E1r4Mgf-0063yV-0O@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox