Fix off-by-one error in PGTYPEStimestamp_fmt_asc
Tomas Vondra <tomas.vondra@postgresql.org>
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
Files
| Path | Change | +/− |
|---|---|---|
| src/interfaces/ecpg/pgtypeslib/timestamp.c | modified | +2 −2 |
| src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c | modified | +20 −4 |
| src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr | modified | +1 −1 |
| src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout | modified | +2 −0 |
| src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc | modified | +16 −0 |
Discussion
- BUG #16143: PGTYPEStimestamp_fmt_asc() returns the incorrect month when the format specifier %b is used. 6 messages · 2019-11-29 → 2019-11-30