diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-05-01 19:29:27 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-05-01 19:29:27 +0000 |
commit | d2d9bd0e04a4b744117ba4edfedb9b3ee441a7be (patch) | |
tree | 4fcbb176884a5dc7fcb0ba188d9b893ffb005c6c | |
parent | 3204d56fd010cd76f68a385d444c695359e708e6 (diff) | |
download | postgresql-d2d9bd0e04a4b744117ba4edfedb9b3ee441a7be.tar.gz postgresql-d2d9bd0e04a4b744117ba4edfedb9b3ee441a7be.zip |
When checking for datetime field overflow, we should allow a fractional-second
part that rounds up to exactly 1.0 second. The previous coding rejected input
like "00:12:57.9999999999999999999999999999", with the exact number of nines
needed to cause failure varying depending on float-timestamp option and
possibly on platform. Obviously this should round up to the next integral
second, if we don't have enough precision to distinguish the value from that.
Per bug #4789 from Robert Kruus.
In passing, fix a missed check for fractional seconds in one copy of the
"is it greater than 24:00:00" code.
Broken all the way back, so patch all the way back.
-rw-r--r-- | src/backend/utils/adt/datetime.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 98c576ec549..a1082fa09e1 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.160.2.8 2009/03/05 14:28:52 heikki Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.160.2.9 2009/05/01 19:29:27 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1138,7 +1138,8 @@ DecodeDateTime(char **field, int *ftype, int nf, */ /* test for > 24:00:00 */ if (tm->tm_hour > 24 || - (tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0))) + (tm->tm_hour == 24 && + (tm->tm_min > 0 || tm->tm_sec > 0 || *fsec > 0))) return DTERR_FIELD_OVERFLOW; break; @@ -2242,17 +2243,16 @@ DecodeTimeOnly(char **field, int *ftype, int nf, if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 || tm->tm_hour > 24 || - /* test for > 24:00:00 */ - (tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0 || + /* test for > 24:00:00 */ + (tm->tm_hour == 24 && + (tm->tm_min > 0 || tm->tm_sec > 0 || *fsec > 0)) || #ifdef HAVE_INT64_TIMESTAMP - *fsec > INT64CONST(0))) || - *fsec < INT64CONST(0) || *fsec >= USECS_PER_SEC) - return DTERR_FIELD_OVERFLOW; + *fsec < INT64CONST(0) || *fsec > USECS_PER_SEC #else - *fsec > 0)) || - *fsec < 0 || *fsec >= 1) - return DTERR_FIELD_OVERFLOW; + *fsec < 0 || *fsec > 1 #endif + ) + return DTERR_FIELD_OVERFLOW; if ((fmask & DTK_TIME_M) != DTK_TIME_M) return DTERR_BAD_FORMAT; @@ -2528,11 +2528,11 @@ DecodeTime(char *str, int fmask, int *tmask, struct pg_tm * tm, fsec_t *fsec) #ifdef HAVE_INT64_TIMESTAMP if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < INT64CONST(0) || - *fsec >= USECS_PER_SEC) + *fsec > USECS_PER_SEC) return DTERR_FIELD_OVERFLOW; #else if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 || - tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < 0 || *fsec >= 1) + tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < 0 || *fsec > 1) return DTERR_FIELD_OVERFLOW; #endif |