pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <bruce@momjian.us>
To: p.nekrasov@fobos-nt.ru
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18614: [ECPG] out of bound in DecodeDateTime
Date: Mon, 14 Oct 2024 17:52:59 -0400
Message-ID: <Zw2Su7kkYYF8nHQY@momjian.us> (raw)
In-Reply-To: <18614-6bbe00117352309e@postgresql.org>
References: <18614-6bbe00117352309e@postgresql.org>

On Thu, Sep 12, 2024 at 08:54:42AM +0000, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      18614
> Logged by:          Pavel Nekrasov
> Email address:      p.nekrasov@fobos-nt.ru
> PostgreSQL version: 17rc1
> Operating system:   Alt 10
> Description:        
> 
> in the line ```if (tm->tm_mday < 1 || tm->tm_mday >
> day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) ``` tm->tm_mon may be equal to
> 0, which will result in reading by indexes -1
> 
> this is possible when calling PGTYPESdate_from_asc or
> PGTYPEStimestamp_from_asc with "str" equal, for example, "AM95000062"

Yes, I agree.  Attached is a non-word-wrapped patch that I plan to apply
to all supported PG versions.

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  When a patient asks the doctor, "Am I going to die?", he means 
  "Am I going to die soon?"

Attachments:

ecpg.diff (text/x-diff, 767B) download diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c index 0d63fe52c5b..bf5976cf03b 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt_common.c +++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c @@ -2327,10 +2327,10 @@ DecodeDateTime(char **field, int *ftype, int nf, return ((fmask & DTK_TIME_M) == DTK_TIME_M) ? 1 : -1; /* - * check for valid day of month, now that we know for sure the month + * check for valid day of month and month, now that we know for sure the month * and year... */ - if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) + if (tm->tm_mon < 1 || tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) return -1; /*

view thread (12+ messages)  latest in thread

Message-ID: <Zw2Su7kkYYF8nHQY@momjian.us>
Permalink:  ../Zw2Su7kkYYF8nHQY@momjian.us/
Also on:    postgresql.org/message-id/Zw2Su7kkYYF8nHQY@momjian.us

 ·  · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: bruce@momjian.us, p.nekrasov@fobos-nt.ru, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18614: [ECPG] out of bound in DecodeDateTime
  In-Reply-To: <Zw2Su7kkYYF8nHQY@momjian.us>

* 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