From 721bd9be4132eadd45c30c3c0ea08dbdbf151fc4 Mon Sep 17 00:00:00 2001 From: "wtc%google.com" Date: Sun, 2 Sep 2007 01:36:40 +0000 Subject: [PATCH] Bug 239371: allow PR_ParseTimeString to accept 5-digit years (but less than 32767, the maximum 16-bit signed integer). The patch is contributed by Dan Witte . r=wtc. git-svn-id: svn://10.0.0.236/trunk@233722 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/nsprpub/pr/src/misc/prtime.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mozilla/nsprpub/pr/src/misc/prtime.c b/mozilla/nsprpub/pr/src/misc/prtime.c index 4212a48cd19..0a0045c8282 100644 --- a/mozilla/nsprpub/pr/src/misc/prtime.c +++ b/mozilla/nsprpub/pr/src/misc/prtime.c @@ -1373,18 +1373,20 @@ PR_ParseTimeStringToExplodedTime( break; s++; - if (*s < '0' || *s > '9') /* third 1, 2, or 4 digits */ + if (*s < '0' || *s > '9') /* third 1, 2, 4, or 5 digits */ break; n3 = (*s++ - '0'); if (*s >= '0' && *s <= '9') n3 = n3*10 + (*s++ - '0'); - if (*s >= '0' && *s <= '9') /* optional digits 3 and 4 */ + if (*s >= '0' && *s <= '9') /* optional digits 3, 4, and 5 */ { n3 = n3*10 + (*s++ - '0'); if (*s < '0' || *s > '9') break; n3 = n3*10 + (*s++ - '0'); + if (*s >= '0' && *s <= '9') + n3 = n3*10 + (*s++ - '0'); } if ((*s >= '0' && *s <= '9') || /* followed by non-alphanum */ @@ -1443,6 +1445,14 @@ PR_ParseTimeStringToExplodedTime( (*end >= 'a' && *end <= 'z')) /* Digits followed by non-punctuation - what's that? */ ; + else if ((end - rest) == 5) /* five digits is a year */ + year = (year < 0 + ? ((rest[0]-'0')*10000L + + (rest[1]-'0')*1000L + + (rest[2]-'0')*100L + + (rest[3]-'0')*10L + + (rest[4]-'0')) + : year); else if ((end - rest) == 4) /* four digits is a year */ year = (year < 0 ? ((rest[0]-'0')*1000L + @@ -1479,7 +1489,7 @@ PR_ParseTimeStringToExplodedTime( } else if ((end - rest) == 1) /* one digit - date */ date = (date < 0 ? (rest[0]-'0') : date); - /* else, three or more than four digits - what's that? */ + /* else, three or more than five digits - what's that? */ break; } @@ -1545,7 +1555,7 @@ PR_ParseTimeStringToExplodedTime( possibly parse this, and in fact, mktime() will do something random (I'm seeing it return "Tue Feb 5 06:28:16 2036", which is no doubt a numerologically significant date... */ - if (month == TT_UNKNOWN || date == -1 || year == -1) + if (month == TT_UNKNOWN || date == -1 || year == -1 || year > PR_INT16_MAX) return PR_FAILURE; memset(result, 0, sizeof(*result));