88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.161 2005/11/22 18: 17:22 momjian Exp $
11+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.162 2005/12/01 17:56:34 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -1013,7 +1013,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
10131013if (tzp == NULL )
10141014return DTERR_BAD_FORMAT ;
10151015
1016+ errno = 0 ;
10161017val = strtol (field [i ],& cp ,10 );
1018+ if (errno == ERANGE )
1019+ return DTERR_FIELD_OVERFLOW ;
10171020
10181021j2date (val ,& tm -> tm_year ,& tm -> tm_mon ,& tm -> tm_mday );
10191022/* Get the time zone from the end of the string */
@@ -1158,7 +1161,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
11581161char * cp ;
11591162int val ;
11601163
1164+ errno = 0 ;
11611165val = strtol (field [i ],& cp ,10 );
1166+ if (errno == ERANGE )
1167+ return DTERR_FIELD_OVERFLOW ;
11621168
11631169/*
11641170 * only a few kinds are allowed to have an embedded
@@ -1915,7 +1921,10 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
19151921break ;
19161922}
19171923
1924+ errno = 0 ;
19181925val = strtol (field [i ],& cp ,10 );
1926+ if (errno == ERANGE )
1927+ return DTERR_FIELD_OVERFLOW ;
19191928
19201929/*
19211930 * only a few kinds are allowed to have an embedded
@@ -2456,11 +2465,17 @@ DecodeTime(char *str, int fmask, int *tmask, struct pg_tm * tm, fsec_t *fsec)
24562465
24572466* tmask = DTK_TIME_M ;
24582467
2468+ errno = 0 ;
24592469tm -> tm_hour = strtol (str ,& cp ,10 );
2470+ if (errno == ERANGE )
2471+ return DTERR_FIELD_OVERFLOW ;
24602472if (* cp != ':' )
24612473return DTERR_BAD_FORMAT ;
24622474str = cp + 1 ;
2475+ errno = 0 ;
24632476tm -> tm_min = strtol (str ,& cp ,10 );
2477+ if (errno == ERANGE )
2478+ return DTERR_FIELD_OVERFLOW ;
24642479if (* cp == '\0' )
24652480{
24662481tm -> tm_sec = 0 ;
@@ -2471,7 +2486,10 @@ DecodeTime(char *str, int fmask, int *tmask, struct pg_tm * tm, fsec_t *fsec)
24712486else
24722487{
24732488str = cp + 1 ;
2489+ errno = 0 ;
24742490tm -> tm_sec = strtol (str ,& cp ,10 );
2491+ if (errno == ERANGE )
2492+ return DTERR_FIELD_OVERFLOW ;
24752493if (* cp == '\0' )
24762494* fsec = 0 ;
24772495else if (* cp == '.' )
@@ -2522,7 +2540,10 @@ DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
25222540
25232541* tmask = 0 ;
25242542
2543+ errno = 0 ;
25252544val = strtol (str ,& cp ,10 );
2545+ if (errno == ERANGE )
2546+ return DTERR_FIELD_OVERFLOW ;
25262547if (cp == str )
25272548return DTERR_BAD_FORMAT ;
25282549
@@ -2809,11 +2830,19 @@ DecodeTimezone(char *str, int *tzp)
28092830if (* str != '+' && * str != '-' )
28102831return DTERR_BAD_FORMAT ;
28112832
2833+ errno = 0 ;
28122834hr = strtol (str + 1 ,& cp ,10 );
2835+ if (errno == ERANGE )
2836+ return DTERR_TZDISP_OVERFLOW ;
28132837
28142838/* explicit delimiter? */
28152839if (* cp == ':' )
2840+ {
2841+ errno = 0 ;
28162842min = strtol (cp + 1 ,& cp ,10 );
2843+ if (errno == ERANGE )
2844+ return DTERR_TZDISP_OVERFLOW ;
2845+ }
28172846/* otherwise, might have run things together... */
28182847else if (* cp == '\0' && strlen (str )> 3 )
28192848{
@@ -3056,7 +3085,10 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
30563085
30573086case DTK_DATE :
30583087case DTK_NUMBER :
3088+ errno = 0 ;
30593089val = strtol (field [i ],& cp ,10 );
3090+ if (errno == ERANGE )
3091+ return DTERR_FIELD_OVERFLOW ;
30603092
30613093if (type == IGNORE_DTF )
30623094type = DTK_SECOND ;