pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix out-of-bound memory access for interval -> char conversion
Date: Mon, 12 Apr 2021 02:32:30 +0000
Message-ID: <E1lVmNK-0002gT-NK@gemulon.postgresql.org> (raw)

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_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/be79debd9688da516f49ba9b825ee2e784d1fab0

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(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1lVmNK-0002gT-NK@gemulon.postgresql.org>
Permalink:  ../E1lVmNK-0002gT-NK@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lVmNK-0002gT-NK@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Fix out-of-bound memory access for interval -> char conversion
  In-Reply-To: <E1lVmNK-0002gT-NK@gemulon.postgresql.org>
  References: <E1lVmNK-0002gT-NK@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