diff options
author | wtc%google.com <devnull@localhost> | 2007-09-02 01:36:40 +0000 |
---|---|---|
committer | wtc%google.com <devnull@localhost> | 2007-09-02 01:36:40 +0000 |
commit | 7347a7daa7c5bdb2a833c020a1c05985e22fefe6 (patch) | |
tree | b165af8fd79ee3d4fff7fdc7582168f64649d25a | |
parent | 13667d0695b8fcd6615b856f4eccf4439c9d5f41 (diff) | |
download | nspr-hg-7347a7daa7c5bdb2a833c020a1c05985e22fefe6.tar.gz |
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 <dwitte@stanford.edu>. r=wtc.
-rw-r--r-- | pr/src/misc/prtime.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/pr/src/misc/prtime.c b/pr/src/misc/prtime.c index 4212a48c..0a0045c8 100644 --- a/pr/src/misc/prtime.c +++ b/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)); |