pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix off-by-one error in PGTYPEStimestamp_fmt_asc
Date: Sat, 30 Nov 2019 14:19:38 +0000
Message-ID: <E1ib3b0-00030v-4O@gemulon.postgresql.org> (raw)

Fix off-by-one error in PGTYPEStimestamp_fmt_asc

When using %b or %B patterns to format a date, the code was simply using
tm_mon as an index into array of month names. But that is wrong, because
tm_mon is 1-based, while array indexes are 0-based. The result is we
either use name of the next month, or a segfault (for December).

Fix by subtracting 1 from tm_mon for both patterns, and add a regression
test triggering the issue. Backpatch to all supported versions (the bug
is there far longer, since at least 2003).

Reported-by: Paul Spencer
Backpatch-through: 9.4
Discussion: https://postgr.es/m/16143-0d861eb8688d3fef%40postgresql.org

Branch
------
REL_10_STABLE

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

Modified Files
--------------
src/interfaces/ecpg/pgtypeslib/timestamp.c         |  4 ++--
.../ecpg/test/expected/pgtypeslib-dt_test.c        | 24 ++++++++++++++++++----
.../ecpg/test/expected/pgtypeslib-dt_test.stderr   |  2 +-
.../ecpg/test/expected/pgtypeslib-dt_test.stdout   |  2 ++
src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc    | 16 +++++++++++++++
5 files changed, 41 insertions(+), 7 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1ib3b0-00030v-4O@gemulon.postgresql.org>
Permalink:  ../E1ib3b0-00030v-4O@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ib3b0-00030v-4O@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: tomas.vondra@postgresql.org
  Subject: Re: pgsql: Fix off-by-one error in PGTYPEStimestamp_fmt_asc
  In-Reply-To: <E1ib3b0-00030v-4O@gemulon.postgresql.org>
  References: <E1ib3b0-00030v-4O@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