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

Commit1f79436

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 parent614119d commit1f79436

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
@@ -2327,6 +2327,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
23272327
GetCurrentDateTime(tmp);
23282328
else
23292329
{
2330+
/* a date has to be specified */
2331+
if ((fmask&DTK_DATE_M)!=DTK_DATE_M)
2332+
returnDTERR_BAD_FORMAT;
23302333
tmp->tm_year=tm->tm_year;
23312334
tmp->tm_mon=tm->tm_mon;
23322335
tmp->tm_mday=tm->tm_mday;
@@ -2354,6 +2357,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
23542357
GetCurrentDateTime(tmp);
23552358
else
23562359
{
2360+
/* a date has to be specified */
2361+
if ((fmask&DTK_DATE_M)!=DTK_DATE_M)
2362+
returnDTERR_BAD_FORMAT;
23572363
tmp->tm_year=tm->tm_year;
23582364
tmp->tm_mon=tm->tm_mon;
23592365
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