Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvDJv-00052Q-LA for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Aug 2019 04:13:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hvDJt-0003Fp-Tv for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Aug 2019 04:13:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvDJt-0003Bf-Hv for pgsql-bugs@lists.postgresql.org; Wed, 07 Aug 2019 04:13:01 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvDJm-0004re-UE for pgsql-bugs@lists.postgresql.org; Wed, 07 Aug 2019 04:13:01 +0000 Received: by mail-lj1-x232.google.com with SMTP id m23so84037237lje.12 for ; Tue, 06 Aug 2019 21:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=cPQ18SFudFWv+29j9K2I0scZQ4/Vbtfwjk7cL6PXMKs=; b=kDleiGxNe7jfufyTWmyAP8k86VWbcpEdxSiU2oMV4XAjgpiE2lTRHeO/GwRwkGK68K uCLu7CzmMTLbHMiKotaJ1BvZXBS9JYAPTg9M41Rt+gUln81BjRsco27dpQeQn8kVR/at aOM/KrvL6QL735pm0Hib0i+nmpcrZfJXpwMTnSbsKn1V5B+8EKt5YXw9seAdikcedA6G XQi8pUU147naor/B90Vg/N0wKcKYfPeYZYG+waaFlklnwTrZ37A0sbfXuqsa6GPRjIgO R7OA2bRJ+V4KTA5ruULr95RpvjC1fN7dC1b8scr5/PqoMTFSYmcMlzmKJSWWH5AWw2q7 Vzsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=cPQ18SFudFWv+29j9K2I0scZQ4/Vbtfwjk7cL6PXMKs=; b=DAoTQw6eZ069R5JsMhQq26nF7xNJe2RfzmLNtM3lfpe/gUfEoXMBs2paMCzcPm5Jbd j+KrfdjSZBQF9FEt0xyfL3UV1ZI65XTRGCRxTiLf5/UyE238SWyQbOifuH7LQYA4lht+ IEm6p1nARc6doT861qeaiwpiUeNME5ji5fYohuLCANuUIcI62NJ4ZZxSPxlvVr982XlO bGsCBsJvt2lIzvMkp2ynfJ+6eZKpm+nYA03g4jPaR2qJ/JGt9eEfBqhfj5skY/ONdqN0 GT4SJYbIe1Cu+Y7EEpOfb225hs3lgSGicIDFMAVy0UTtdrQMiUrysMoI7MKEJ7FEXUlX DHGw== X-Gm-Message-State: APjAAAVZ8qZrMImRx6KaBSwcgr8weFoDK4dNk+rsvW1p6Owr7PaICgVx KAk6l3ATCd3vRjKiLH96l/fcGVlE X-Google-Smtp-Source: APXvYqyWLSwL3GiS81lpmw1TQPO8bFLBwUj51fZwRo8mQm6tdy2BnBniB1QBH746Jzi3Jwel0kdk1w== X-Received: by 2002:a2e:8591:: with SMTP id b17mr3536600lji.71.1565151170742; Tue, 06 Aug 2019 21:12:50 -0700 (PDT) Received: from [1.0.0.7] ([178.155.4.82]) by smtp.gmail.com with ESMTPSA id u17sm16194826lfq.69.2019.08.06.21.12.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 21:12:49 -0700 (PDT) Subject: Re: BUG #15910: Valgrind-detected error in DecodeTimeOnly To: Michael Paquier Cc: pgsql-bugs@lists.postgresql.org References: <15910-2eba5106b9aa0c61@postgresql.org> <0aaf1cb9-0f85-e786-fb32-b3d68b80d027@gmail.com> <97ac4fe2-65d9-6a7b-76e0-5ad3b06cd9dc@gmail.com> <20190806062111.GG32256@paquier.xyz> From: Alexander Lakhin Message-ID: Date: Wed, 7 Aug 2019 07:12:48 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190806062111.GG32256@paquier.xyz> Content-Type: multipart/mixed; boundary="------------CF427979F3F44E17A8D5E163" Content-Language: ru-RU List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------CF427979F3F44E17A8D5E163 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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 --------------CF427979F3F44E17A8D5E163 Content-Type: text/x-patch; name="fix-DecodeTimeOnly-v3.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-DecodeTimeOnly-v3.patch" 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; --------------CF427979F3F44E17A8D5E163--