From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: paul@intekon.com
Subject: BUG #16143: PGTYPEStimestamp_fmt_asc() returns the incorrect month when the format specifier %b is used.
Date: Fri, 29 Nov 2019 19:40:37 +0000
Message-ID: <16143-0d861eb8688d3fef@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 16143
Logged by: Paul Spencer
Email address: paul@intekon.com
PostgreSQL version: 11.5
Operating system: Redhat and Debian
Description:
PGTYPEStimestamp_fmt_asc() returns the incorrect month when the format
specifier %b is used. The returned month is one greater then the expected
month. If the expected month is “Dec”, the application may crash with a
segment fault. The format specifier %B has a similar issue.
** Investigation Notes
- The month is increased by one at line 143 in timestamp2tm() defined in
timestamp.c https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/ecpg/pgtypeslib/timestam...
- The month number is converted to the abbreviation at line 337 in
dttofmtasc_replace() defined in timestamp.c https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/ecpg/pgtypeslib/timestam...
- Month abbreviations are defined at line 499 in dt_common.c
https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/ecpg/pgtypeslib/dt_commo...
***
* Use Case
***
pi@raspberrypi4:~/projects/postgres_month_date $ ./pg_month_date
PostgreSQL timestamp_fmt_asc()
PGTYPEStimestamp_to_asc returns 1999-01-08 04:06:06
Format string = %Y-%m-%d %H:%M:%S, Formated Date = 1999-01-08 04:06:06
Format string = %Y-%b-%d %H:%M:%S, Formated Date = 1999-Feb-08 04:06:06
pi@raspberrypi4:~/projects/postgres_month_date $
***
* Source code for the use case
***
/*
* pg_month_date.c
*/
#include <stdio.h>
#include <string.h>
#include "pgtypes_timestamp.h"
int main(int argc, char **argv)
{
char formatString[255] = "";
char stringBuffer[255] = "";
timestamp testTimestamp;
char * endPtr = NULL;
printf("%s\n","PostgreSQL timestamp_fmt_asc()");
testTimestamp = PGTYPEStimestamp_from_asc("1999-01-08 04:06:06",
&endPtr);
printf("PGTYPEStimestamp_to_asc returns %s\n",
PGTYPEStimestamp_to_asc(testTimestamp));
strncpy(formatString, "%Y-%m-%d %H:%M:%S", sizeof(formatString));
PGTYPEStimestamp_fmt_asc(&testTimestamp, stringBuffer,
sizeof(stringBuffer),formatString);
printf( "Format string = %s, Formated Date = %s\n", formatString ,
stringBuffer);
strncpy(formatString, "%Y-%b-%d %H:%M:%S", sizeof(formatString));
PGTYPEStimestamp_fmt_asc(&testTimestamp, stringBuffer,
sizeof(stringBuffer),formatString);
printf( "Format string = %s, Formated Date = %s\n", formatString ,
stringBuffer);
return 0;
}
Paul Spencer
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, paul@intekon.com
Subject: Re: BUG #16143: PGTYPEStimestamp_fmt_asc() returns the incorrect month when the format specifier %b is used.
In-Reply-To: <16143-0d861eb8688d3fef@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