Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd16d241

Browse files
committed
Fix some incorrect parsing of time with time zone strings
When parsing a timetz string with a dynamic timezone abbreviation or atimezone not specified, it was possible to generate incorrect timestampsbased on a date which uses some non-initialized variables if the inputstring did not specify fully a date to parse. This is already checkedwhen a full timezone spec is included in the input string, but the twoother cases mentioned above missed the same checks.This gets fixed by generating an error as this input is invalid, or inshort when a date is not fully specified.Valgrind was complaining about this problem.Bug: #15910Author: Alexander LakhinDiscussion:https://postgr.es/m/15910-2eba5106b9aa0c61@postgresql.orgBackpatch-through: 9.4
1 parent113b3d9 commitd16d241

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
23012301
GetCurrentDateTime(tmp);
23022302
else
23032303
{
2304+
/* a date has to be specified */
2305+
if ((fmask&DTK_DATE_M)!=DTK_DATE_M)
2306+
returnDTERR_BAD_FORMAT;
23042307
tmp->tm_year=tm->tm_year;
23052308
tmp->tm_mon=tm->tm_mon;
23062309
tmp->tm_mday=tm->tm_mday;
@@ -2328,6 +2331,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
23282331
GetCurrentDateTime(tmp);
23292332
else
23302333
{
2334+
/* a date has to be specified */
2335+
if ((fmask&DTK_DATE_M)!=DTK_DATE_M)
2336+
returnDTERR_BAD_FORMAT;
23312337
tmp->tm_year=tm->tm_year;
23322338
tmp->tm_mon=tm->tm_mon;
23332339
tmp->tm_mday=tm->tm_mday;

‎src/test/regress/expected/timetz.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ INSERT INTO TIMETZ_TBL VALUES ('15:36:39 America/New_York');
1919
ERROR: invalid input syntax for type time with time zone: "15:36:39 America/New_York"
2020
LINE 1: INSERT INTO TIMETZ_TBL VALUES ('15:36:39 America/New_York');
2121
^
22+
-- this should fail (timezone not specified without a date)
23+
INSERT INTO TIMETZ_TBL VALUES ('15:36:39 m2');
24+
ERROR: invalid input syntax for type time with time zone: "15:36:39 m2"
25+
LINE 1: INSERT INTO TIMETZ_TBL VALUES ('15:36:39 m2');
26+
^
27+
-- this should fail (dynamic timezone abbreviation without a date)
28+
INSERT INTO TIMETZ_TBL VALUES ('15:36:39 MSK m2');
29+
ERROR: invalid input syntax for type time with time zone: "15:36:39 MSK m2"
30+
LINE 1: INSERT INTO TIMETZ_TBL VALUES ('15:36:39 MSK m2');
31+
^
2232
SELECT f1 AS "Time TZ" FROM TIMETZ_TBL;
2333
Time TZ
2434
----------------

‎src/test/regress/sql/timetz.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ INSERT INTO TIMETZ_TBL VALUES ('2003-03-07 15:36:39 America/New_York');
1919
INSERT INTO TIMETZ_TBLVALUES ('2003-07-07 15:36:39 America/New_York');
2020
-- this should fail (the timezone offset is not known)
2121
INSERT INTO TIMETZ_TBLVALUES ('15:36:39 America/New_York');
22+
-- this should fail (timezone not specified without a date)
23+
INSERT INTO TIMETZ_TBLVALUES ('15:36:39 m2');
24+
-- this should fail (dynamic timezone abbreviation without a date)
25+
INSERT INTO TIMETZ_TBLVALUES ('15:36:39 MSK m2');
26+
2227

2328
SELECT f1AS"Time TZ"FROM TIMETZ_TBL;
2429

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp