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 1huVyT-0004lV-SU for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Aug 2019 05:56:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1huVyS-0007uT-Py for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Aug 2019 05:56:00 +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 1huVyS-0007uM-GZ for pgsql-bugs@lists.postgresql.org; Mon, 05 Aug 2019 05:56:00 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1huVyQ-0001iG-8G for pgsql-bugs@lists.postgresql.org; Mon, 05 Aug 2019 05:56:00 +0000 Received: by mail-lf1-x136.google.com with SMTP id x3so57050100lfc.0 for ; Sun, 04 Aug 2019 22:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=VS5Yh07fvgI70nqnRckN/Xw3HfQycGeh1ESjVmYNQMM=; b=UaNlu3jYQOWY9NQRx/YQ7H0WEYWOOpM4q+iJWTWz5MfMuGBTkVkaSSrWPVGQb2xT/v Q2jZYI5E1wIhwI/fZ2fiQ5nHYuo4tPUCZj9+Q86sV0D/0thcmt6FQoZ/ybxrtjVkovLK LPLtzCF/plpFSbSSB9TddBJQu0EudrgR2weuHG6qpb4hmNRAP5uRBK4TFhjRPqlh9erp DYd9BQh7NzvsmpegPqiOpLCrhy5aCaiN5nhUIK73PTM1WhDEM+3dFfltVyEAXeF84CSh QMF9P6aMrCBqShfVmQ9sMTSlFFZ5MLtrmZwlXXcTU2LowLNTPL0/wxPawPjf8+8Mfl4y ZiPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=VS5Yh07fvgI70nqnRckN/Xw3HfQycGeh1ESjVmYNQMM=; b=HJ5AW1o01y/lfPPJt45e1yOi91TdIyBi/wvlTU9Cj9vdVIOYhanzW015y/M03ewUN+ t3T61FmdDeVkALK/rzD0AKp5sABJ35ylHdR/oxf3BhpClbwTgM6Ify1nmRhSOg0NwfcL kGyVY6atSagfd52Ph0pjQIccZApe5PYSXAJ0AH1wXf3uJFIqDB3x12vez4J/LklchkoW v2Kvf9G18R8u5cA4962a6BQB8rkGN/lqA4uQ7g2yD8LJbyp+Uzjrbt90JSye4Wbplpts MsTSaJGaDWWTw1zCW8co4Azx97pzDn6CnLQ2+hq9Be0NGvTxPOn1HoxK5c5gq7ID+1rm Z2VA== X-Gm-Message-State: APjAAAX4EBsY8tTrq3lJg1DGHamEbHezwCCmi0O5Vinu3jzRsejAxOHn nO25sLQf4LEJqjdEpuvbu+bCgkIw X-Google-Smtp-Source: APXvYqyquBDnL5p2VwngpkEcdqL3NKronJF/RsTcc6AS/eEqBVZ5nom+PhHkcymMXqKxPxExs3BZxg== X-Received: by 2002:ac2:5c1d:: with SMTP id r29mr18865937lfp.72.1564984556924; Sun, 04 Aug 2019 22:55:56 -0700 (PDT) Received: from [1.0.0.7] ([178.155.4.181]) by smtp.gmail.com with ESMTPSA id j14sm17025043ljc.67.2019.08.04.22.55.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Aug 2019 22:55:56 -0700 (PDT) Subject: Re: BUG #15910: Valgrind-detected error in DecodeTimeOnly From: Alexander Lakhin To: pgsql-bugs@lists.postgresql.org References: <15910-2eba5106b9aa0c61@postgresql.org> <0aaf1cb9-0f85-e786-fb32-b3d68b80d027@gmail.com> Message-ID: <97ac4fe2-65d9-6a7b-76e0-5ad3b06cd9dc@gmail.com> Date: Mon, 5 Aug 2019 08:55:55 +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: <0aaf1cb9-0f85-e786-fb32-b3d68b80d027@gmail.com> Content-Type: multipart/mixed; boundary="------------66E49616F7563FC7EE9EF201" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------66E49616F7563FC7EE9EF201 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello hackers, 16.07.2019 19:24, Alexander Lakhin wrote: >> Bug reference: 15910 >> Logged by: Alexander Lakhin >> Email address: exclusion@gmail.com >> PostgreSQL version: 12beta2 >> Operating system: Ubuntu 18.04 >> Description: >> >> When executing the following query: >> SELECT time with time zone '04:05:06 m2'; >> I get a strange result: >> timetz >> ------------------- >> 04:05:06+02:30:17 >> > The attached patch fixes this issue. In case this bug is worth fixing, please look at the improved patch with the corresponding regression test. Best regards, Alexander --------------66E49616F7563FC7EE9EF201 Content-Type: text/x-patch; name="fix-DecodeTimeOnly-v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-DecodeTimeOnly-v2.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..32609dfdc8 100644 --- a/src/test/regress/expected/timetz.out +++ b/src/test/regress/expected/timetz.out @@ -19,6 +19,11 @@ 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'); + ^ 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..a0a7cc4eb2 100644 --- a/src/test/regress/sql/timetz.sql +++ b/src/test/regress/sql/timetz.sql @@ -19,6 +19,9 @@ 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'); + SELECT f1 AS "Time TZ" FROM TIMETZ_TBL; --------------66E49616F7563FC7EE9EF201--