Commit 1b113a23 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Change rules for interpreting date/time input to disallow 1 and 3 character

 years. Rejects dates like '0.085', which were accepted previously.
parent bcd488d0
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.44 2000/03/16 14:36:51 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.45 2000/03/29 03:57:18 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1367,8 +1367,11 @@ DecodeNumber(int flen, char *str, int fmask, ...@@ -1367,8 +1367,11 @@ DecodeNumber(int flen, char *str, int fmask,
* more, but we now test first for a three-digit doy so anything * more, but we now test first for a three-digit doy so anything
* bigger than two digits had better be an explicit year. - thomas * bigger than two digits had better be an explicit year. - thomas
* 1999-01-09 * 1999-01-09
* Back to requiring a 4 digit year.
* We accept a two digit year farther down.
* - thomas 2000-03-28
*/ */
else if (flen > 2) else if (flen >= 4)
{ {
*tmask = DTK_M(YEAR); *tmask = DTK_M(YEAR);
...@@ -1382,14 +1385,16 @@ DecodeNumber(int flen, char *str, int fmask, ...@@ -1382,14 +1385,16 @@ DecodeNumber(int flen, char *str, int fmask,
tm->tm_year = val; tm->tm_year = val;
} }
/* already have year? then could be month */ /* already have year? then could be month */
else if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(MONTH))) else if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(MONTH)))
&& ((val >= 1) && (val <= 12))) && ((val >= 1) && (val <= 12)))
{ {
*tmask = DTK_M(MONTH); *tmask = DTK_M(MONTH);
tm->tm_mon = val; tm->tm_mon = val;
/* no year and EuroDates enabled? then could be day */
} }
/* no year and EuroDates enabled? then could be day */
else if ((EuroDates || (fmask & DTK_M(MONTH))) else if ((EuroDates || (fmask & DTK_M(MONTH)))
&& (!(fmask & DTK_M(YEAR)) && !(fmask & DTK_M(DAY))) && (!(fmask & DTK_M(YEAR)) && !(fmask & DTK_M(DAY)))
&& ((val >= 1) && (val <= 31))) && ((val >= 1) && (val <= 31)))
...@@ -1409,7 +1414,11 @@ DecodeNumber(int flen, char *str, int fmask, ...@@ -1409,7 +1414,11 @@ DecodeNumber(int flen, char *str, int fmask,
*tmask = DTK_M(DAY); *tmask = DTK_M(DAY);
tm->tm_mday = val; tm->tm_mday = val;
} }
else if (!(fmask & DTK_M(YEAR))) /* Check for 2 or 4 or more digits, but currently we reach here
* only if two digits. - thomas 2000-03-28
*/
else if (!(fmask & DTK_M(YEAR))
&& ((flen >= 4) || (flen == 2)))
{ {
*tmask = DTK_M(YEAR); *tmask = DTK_M(YEAR);
tm->tm_year = val; tm->tm_year = val;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment