pgsql: Fix out-of-bound memory access for interval -> char conversion

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix out-of-bound memory access for interval -> char conversion
Date: 2021-04-12 02:32:30
Message-ID: E1lVmNK-0002gW-Nj@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix out-of-bound memory access for interval -> char conversion

Using Roman numbers (via "RM" or "rm") for a conversion to calculate a
number of months has never considered the case of negative numbers,
where a conversion could easily cause out-of-bound memory accesses. The
conversions in themselves were not completely consistent either, as
specifying 12 would result in NULL, but it should mean XII.

This commit reworks the conversion calculation to have a more
consistent behavior:
- If the number of months and years is 0, return NULL.
- If the number of months is positive, return the exact month number.
- If the number of months is negative, do a backward calculation, with
-1 meaning December, -2 November, etc.

Reported-by: Theodor Arsenij Larionov-Trichkin
Author: Julien Rouhaud
Discussion: https://postgr.es/m/16953-f255a18f8c51f1d5@postgresql.org
backpatch-through: 9.6

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/82dd5706ee5a5fc4db962fe1a672b4f71ab51612

Modified Files
--------------
src/backend/utils/adt/formatting.c | 63 +++++++++++++++++++++++++++------
src/test/regress/expected/timestamp.out | 36 +++++++++++++++++++
src/test/regress/sql/timestamp.sql | 6 ++++
3 files changed, 95 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2021-04-12 03:35:20 pgsql: Allocate access strategy in parallel VACUUM workers.
Previous Message tsunakawa.takay@fujitsu.com 2021-04-12 01:40:36 RE: pgsql: Add a new GUC and a reloption to enable inserts in parallel-mode