pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15910: Valgrind-detected error in DecodeTimeOnly
Date: Wed, 7 Aug 2019 07:12:48 +0300
Message-ID: <a8d43cee-aa0d-7962-8fb0-0fcfa9a422ba@gmail.com> (raw)
In-Reply-To: <20190806062111.GG32256@paquier.xyz>
References: <15910-2eba5106b9aa0c61@postgresql.org>
	<0aaf1cb9-0f85-e786-fb32-b3d68b80d027@gmail.com>
	<97ac4fe2-65d9-6a7b-76e0-5ad3b06cd9dc@gmail.com>
	<20190806062111.GG32256@paquier.xyz>

Hello Michael,
06.08.2019 9:21, Michael Paquier wrote:
> On Mon, Aug 05, 2019 at 08:55:55AM +0300, Alexander Lakhin wrote:
>> In case this bug is worth fixing, please look at the improved patch with
>> the corresponding regression test.
> In this case, DecodeSpecial() decodes the abbrevation passed down as
> UNITS, which is right on its own.  Still, afterwards the code fails to
> correctly set a date from the string present.  In short, your
> suggestion of fix looks good to me and that's more consistent with the
> full timezone spec case.  The test case you added in this patch
> triggers the error in the code path where the timezone is not
> specified.  Could you add an extra test case for the timezone
> abbreviation?
Sure, please look at the improved fix.

Best regards,
Alexander

Attachments:

fix-DecodeTimeOnly-v3.patch (text/x-patch, 2.7K) download diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 972fcd26a2..1f8b0183f3 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -2280,6 +2280,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf, GetCurrentDateTime(tmp); else { + /* a date has to be fully specified */ + if ((fmask & DTK_DATE_M) != DTK_DATE_M) + return DTERR_BAD_FORMAT; tmp->tm_year = tm->tm_year; tmp->tm_mon = tm->tm_mon; tmp->tm_mday = tm->tm_mday; @@ -2307,6 +2310,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf, GetCurrentDateTime(tmp); else { + /* a date has to be fully specified */ + if ((fmask & DTK_DATE_M) != DTK_DATE_M) + return DTERR_BAD_FORMAT; tmp->tm_year = tm->tm_year; tmp->tm_mon = tm->tm_mon; tmp->tm_mday = tm->tm_mday; diff --git a/src/test/regress/expected/timetz.out b/src/test/regress/expected/timetz.out index 33ff8e18c9..a25f468cbb 100644 --- a/src/test/regress/expected/timetz.out +++ b/src/test/regress/expected/timetz.out @@ -19,6 +19,16 @@ INSERT INTO TIMETZ_TBL VALUES ('15:36:39 America/New_York'); ERROR: invalid input syntax for type time with time zone: "15:36:39 America/New_York" LINE 1: INSERT INTO TIMETZ_TBL VALUES ('15:36:39 America/New_York'); ^ +-- this should fail (the time specification is invalid) +INSERT INTO TIMETZ_TBL VALUES ('15:36:39 m2'); +ERROR: invalid input syntax for type time with time zone: "15:36:39 m2" +LINE 1: INSERT INTO TIMETZ_TBL VALUES ('15:36:39 m2'); + ^ +-- this should fail too (the same with a dynamic timezone abbreviation) +INSERT INTO TIMETZ_TBL VALUES ('15:36:39 MSK m2'); +ERROR: invalid input syntax for type time with time zone: "15:36:39 MSK m2" +LINE 1: INSERT INTO TIMETZ_TBL VALUES ('15:36:39 MSK m2'); + ^ SELECT f1 AS "Time TZ" FROM TIMETZ_TBL; Time TZ ---------------- diff --git a/src/test/regress/sql/timetz.sql b/src/test/regress/sql/timetz.sql index c41686a5e2..58c4b6e1bc 100644 --- a/src/test/regress/sql/timetz.sql +++ b/src/test/regress/sql/timetz.sql @@ -19,6 +19,11 @@ INSERT INTO TIMETZ_TBL VALUES ('2003-03-07 15:36:39 America/New_York'); INSERT INTO TIMETZ_TBL VALUES ('2003-07-07 15:36:39 America/New_York'); -- this should fail (the timezone offset is not known) INSERT INTO TIMETZ_TBL VALUES ('15:36:39 America/New_York'); +-- this should fail (the time specification is invalid) +INSERT INTO TIMETZ_TBL VALUES ('15:36:39 m2'); +-- this should fail too (the same with a dynamic timezone abbreviation) +INSERT INTO TIMETZ_TBL VALUES ('15:36:39 MSK m2'); + SELECT f1 AS "Time TZ" FROM TIMETZ_TBL;

view thread (8+ messages)  latest in thread

Message-ID: <a8d43cee-aa0d-7962-8fb0-0fcfa9a422ba@gmail.com>
Permalink:  ../a8d43cee-aa0d-7962-8fb0-0fcfa9a422ba@gmail.com/
Also on:    postgresql.org/message-id/a8d43cee-aa0d-7962-8fb0-0fcfa9a422ba@gmail.com

 ·  · 

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: exclusion@gmail.com, michael@paquier.xyz, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #15910: Valgrind-detected error in DecodeTimeOnly
  In-Reply-To: <a8d43cee-aa0d-7962-8fb0-0fcfa9a422ba@gmail.com>

* 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