pgsql: Fix off-by-one error in PGTYPEStimestamp_fmt_asc

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix off-by-one error in PGTYPEStimestamp_fmt_asc
Date: 2019-11-30 14:19:50
Message-ID: E1ib3bC-00031c-ED@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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
------
REL9_6_STABLE

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

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

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2019-11-30 14:20:00 pgsql: Fix off-by-one error in PGTYPEStimestamp_fmt_asc
Previous Message Tomas Vondra 2019-11-30 14:19:38 pgsql: Fix off-by-one error in PGTYPEStimestamp_fmt_asc