mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
parsedate: fix date parsing for systems with 32 bit long
Make curl_getdate() handle dates before 1970 as well (returning negative values). Make test 517 test dates for 64 bit time_t. This fixes bug (3) mentioned in #2238 Closes #2250
This commit is contained in:
parent
1433e4645b
commit
1c39128d97
19
configure.ac
19
configure.ac
@ -5,7 +5,7 @@
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
# Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file COPYING, which
|
||||
# you should have received as part of this distribution. The terms
|
||||
@ -3483,6 +3483,23 @@ AC_CHECK_TYPE([bool],[
|
||||
#endif
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING([if time_t is unsigned])
|
||||
AC_RUN_IFELSE([
|
||||
AC_LANG_SOURCE([[
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
time_t t = ULONG_MAX;
|
||||
return (t > 0);
|
||||
]])] ,[
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE(HAVE_TIME_T_UNSIGNED, 1, [Define this if time_t is unsigned])
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
],[
|
||||
dnl cross-compiling, most systems are unsigned
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
|
||||
CURL_CONFIGURE_CURL_SOCKLEN_T
|
||||
|
||||
CURL_CONFIGURE_PULL_SYS_POLL
|
||||
|
@ -5,7 +5,7 @@
|
||||
.\" * | (__| |_| | _ <| |___
|
||||
.\" * \___|\___/|_| \_\_____|
|
||||
.\" *
|
||||
.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
.\" *
|
||||
.\" * This software is licensed as described in the file COPYING, which
|
||||
.\" * you should have received as part of this distribution. The terms
|
||||
@ -96,13 +96,15 @@ only ones RFC 7231 says HTTP applications may use.
|
||||
This function returns -1 when it fails to parse the date string. Otherwise it
|
||||
returns the number of seconds as described.
|
||||
|
||||
If the year is larger than 2037 on systems with 32 bit time_t, this function
|
||||
will return 0x7fffffff (since that is the largest possible signed 32 bit
|
||||
number).
|
||||
On systems with a signed 32 bit time_t: if the year is larger than 2037 or
|
||||
less than 1903, this function will return -1.
|
||||
|
||||
Having a 64 bit time_t is not a guarantee that dates beyond 03:14:07 UTC,
|
||||
January 19, 2038 will work fine. On systems with a 64 bit time_t but with a
|
||||
crippled mktime(), \fIcurl_getdate(3)\fP will return -1 in this case.
|
||||
On systems with an unsigned 32 bit time_t: if the year is larger than 2106 or
|
||||
less than 1970, this function will return -1.
|
||||
|
||||
On systems with 64 bit time_t: if the year is less than 1583, this function
|
||||
will return -1. (The Gregorian calendar was first introduced 1582 so no "real"
|
||||
dates in this way of doing dates existed before then.)
|
||||
.SH "SEE ALSO"
|
||||
.BR curl_easy_escape "(3), " curl_easy_unescape "(3), "
|
||||
.BR CURLOPT_TIMECONDITION "(3), " CURLOPT_TIMEVALUE "(3) "
|
||||
|
@ -424,6 +424,24 @@
|
||||
#endif
|
||||
#define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
|
||||
|
||||
#if (SIZEOF_TIME_T == 4)
|
||||
# ifdef HAVE_TIME_T_UNSIGNED
|
||||
# define TIME_T_MAX UINT_MAX
|
||||
# define TIME_T_MIN 0
|
||||
# else
|
||||
# define TIME_T_MAX INT_MAX
|
||||
# define TIME_T_MIN INT_MIN
|
||||
# endif
|
||||
#else
|
||||
# ifdef HAVE_TIME_T_UNSIGNED
|
||||
# define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
|
||||
# define TIME_T_MIN 0
|
||||
# else
|
||||
# define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
|
||||
# define TIME_T_MIN -0x10000000000000000
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Arg 2 type for gethostname in case it hasn't been defined in config file.
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -276,26 +276,23 @@ struct my_tm {
|
||||
int tm_hour;
|
||||
int tm_mday;
|
||||
int tm_mon;
|
||||
int tm_year;
|
||||
int tm_year; /* full year */
|
||||
};
|
||||
|
||||
/* struct tm to time since epoch in GMT time zone.
|
||||
* This is similar to the standard mktime function but for GMT only, and
|
||||
* doesn't suffer from the various bugs and portability problems that
|
||||
* some systems' implementations have.
|
||||
*
|
||||
* Returns 0 on success, otherwise non-zero.
|
||||
*/
|
||||
static time_t my_timegm(struct my_tm *tm)
|
||||
static void my_timegm(struct my_tm *tm, time_t *t)
|
||||
{
|
||||
static const int month_days_cumulative [12] =
|
||||
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
|
||||
int month, year, leap_days;
|
||||
|
||||
if(tm->tm_year < 70)
|
||||
/* we don't support years before 1970 as they will cause this function
|
||||
to return a negative value */
|
||||
return -1;
|
||||
|
||||
year = tm->tm_year + 1900;
|
||||
year = tm->tm_year;
|
||||
month = tm->tm_mon;
|
||||
if(month < 0) {
|
||||
year += (11 - month) / 12;
|
||||
@ -310,9 +307,9 @@ static time_t my_timegm(struct my_tm *tm)
|
||||
leap_days = ((leap_days / 4) - (leap_days / 100) + (leap_days / 400)
|
||||
- (1969 / 4) + (1969 / 100) - (1969 / 400));
|
||||
|
||||
return ((((time_t) (year - 1970) * 365
|
||||
+ leap_days + month_days_cumulative [month] + tm->tm_mday - 1) * 24
|
||||
+ tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
|
||||
*t = ((((time_t) (year - 1970) * 365
|
||||
+ leap_days + month_days_cumulative[month] + tm->tm_mday - 1) * 24
|
||||
+ tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -462,7 +459,7 @@ static int parsedate(const char *date, time_t *output)
|
||||
if(!found && (dignext == DATE_YEAR) && (yearnum == -1)) {
|
||||
yearnum = val;
|
||||
found = TRUE;
|
||||
if(yearnum < 1900) {
|
||||
if(yearnum < 100) {
|
||||
if(yearnum > 70)
|
||||
yearnum += 1900;
|
||||
else
|
||||
@ -491,18 +488,39 @@ static int parsedate(const char *date, time_t *output)
|
||||
/* lacks vital info, fail */
|
||||
return PARSEDATE_FAIL;
|
||||
|
||||
#if SIZEOF_TIME_T < 5
|
||||
/* 32 bit time_t can only hold dates to the beginning of 2038 */
|
||||
if(yearnum > 2037) {
|
||||
*output = 0x7fffffff;
|
||||
return PARSEDATE_LATER;
|
||||
#ifdef HAVE_TIME_T_UNSIGNED
|
||||
if(yearnum < 1970) {
|
||||
/* only positive numbers cannot return earlier */
|
||||
*output = TIME_T_MIN;
|
||||
return PARSEDATE_SOONER;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(yearnum < 1970) {
|
||||
*output = 0;
|
||||
#if (SIZEOF_TIME_T < 5)
|
||||
|
||||
#if HAVE_TIME_T_UNSIGNED
|
||||
/* an unsigned 32 bit time_t can only hold dates to 2106 */
|
||||
if(yearnum > 2105) {
|
||||
*output = TIME_T_MAX;
|
||||
return PARSEDATE_LATER;
|
||||
}
|
||||
#else
|
||||
/* a signed 32 bit time_t can only hold dates to the beginning of 2038 */
|
||||
if(yearnum > 2037) {
|
||||
*output = TIME_T_MAX;
|
||||
return PARSEDATE_LATER;
|
||||
}
|
||||
if(yearnum < 1903) {
|
||||
*output = TIME_T_MIN;
|
||||
return PARSEDATE_SOONER;
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
/* The Gregorian calendar was introduced 1582 */
|
||||
if(yearnum < 1583)
|
||||
return PARSEDATE_FAIL;
|
||||
#endif
|
||||
|
||||
if((mdaynum > 31) || (monnum > 11) ||
|
||||
(hournum > 23) || (minnum > 59) || (secnum > 60))
|
||||
@ -513,31 +531,25 @@ static int parsedate(const char *date, time_t *output)
|
||||
tm.tm_hour = hournum;
|
||||
tm.tm_mday = mdaynum;
|
||||
tm.tm_mon = monnum;
|
||||
tm.tm_year = yearnum - 1900;
|
||||
tm.tm_year = yearnum;
|
||||
|
||||
/* my_timegm() returns a time_t. time_t is often 32 bits, even on many
|
||||
architectures that feature 64 bit 'long'.
|
||||
|
||||
Some systems have 64 bit time_t and deal with years beyond 2038. However,
|
||||
even on some of the systems with 64 bit time_t mktime() returns -1 for
|
||||
dates beyond 03:14:07 UTC, January 19, 2038. (Such as AIX 5100-06)
|
||||
/* my_timegm() returns a time_t. time_t is often 32 bits, sometimes even on
|
||||
architectures that feature 64 bit 'long' but ultimately time_t is the
|
||||
correct data type to use.
|
||||
*/
|
||||
t = my_timegm(&tm);
|
||||
my_timegm(&tm, &t);
|
||||
|
||||
/* time zone adjust (cast t to int to compare to negative one) */
|
||||
if(-1 != (int)t) {
|
||||
/* Add the time zone diff between local time zone and GMT. */
|
||||
if(tzoff == -1)
|
||||
tzoff = 0;
|
||||
|
||||
/* Add the time zone diff between local time zone and GMT. */
|
||||
long delta = (long)(tzoff!=-1?tzoff:0);
|
||||
|
||||
if((delta>0) && (t > LONG_MAX - delta)) {
|
||||
*output = 0x7fffffff;
|
||||
return PARSEDATE_LATER; /* time_t overflow */
|
||||
}
|
||||
|
||||
t += delta;
|
||||
if((tzoff > 0) && (t > TIME_T_MAX - tzoff)) {
|
||||
*output = TIME_T_MAX;
|
||||
return PARSEDATE_LATER; /* time_t overflow */
|
||||
}
|
||||
|
||||
t += tzoff;
|
||||
|
||||
*output = t;
|
||||
|
||||
return PARSEDATE_OK;
|
||||
@ -551,6 +563,10 @@ time_t curl_getdate(const char *p, const time_t *now)
|
||||
|
||||
switch(rc) {
|
||||
case PARSEDATE_OK:
|
||||
if(parsed == -1)
|
||||
/* avoid returning -1 for a working scenario */
|
||||
parsed++;
|
||||
/* fallthrough */
|
||||
case PARSEDATE_LATER:
|
||||
case PARSEDATE_SOONER:
|
||||
return parsed;
|
||||
|
@ -32,96 +32,6 @@ nothing
|
||||
# Verify data after the test has been "shot"
|
||||
<verify>
|
||||
<stdout>
|
||||
0: Sun, 06 Nov 1994 08:49:37 GMT => 784111777
|
||||
1: Sunday, 06-Nov-94 08:49:37 GMT => 784111777
|
||||
2: Sun Nov 6 08:49:37 1994 => 784111777
|
||||
3: 06 Nov 1994 08:49:37 GMT => 784111777
|
||||
4: 06-Nov-94 08:49:37 GMT => 784111777
|
||||
5: Nov 6 08:49:37 1994 => 784111777
|
||||
6: 06 Nov 1994 08:49:37 => 784111777
|
||||
7: 06-Nov-94 08:49:37 => 784111777
|
||||
8: 1994 Nov 6 08:49:37 => 784111777
|
||||
9: GMT 08:49:37 06-Nov-94 Sunday => 784111777
|
||||
10: 94 6 Nov 08:49:37 => 784111777
|
||||
11: 1994 Nov 6 => 784080000
|
||||
12: 06-Nov-94 => 784080000
|
||||
13: Sun Nov 6 94 => 784080000
|
||||
14: 1994.Nov.6 => 784080000
|
||||
15: Sun/Nov/6/94/GMT => 784080000
|
||||
16: Sun, 06 Nov 1994 08:49:37 CET => 784108177
|
||||
17: 06 Nov 1994 08:49:37 EST => 784129777
|
||||
18: Sun, 12 Sep 2004 15:05:58 -0700 => 1095026758
|
||||
19: Sat, 11 Sep 2004 21:32:11 +0200 => 1094931131
|
||||
20: 20040912 15:05:58 -0700 => 1095026758
|
||||
21: 20040911 +0200 => 1094853600
|
||||
22: Thu, 01-Jan-1970 00:59:59 GMT => 3599
|
||||
23: Thu, 01-Jan-1970 01:00:00 GMT => 3600
|
||||
24: Sat, 15-Apr-17 21:01:22 GMT => 1492290082
|
||||
25: Thu, 19-Apr-2007 16:00:00 GMT => 1176998400
|
||||
26: Wed, 25 Apr 2007 21:02:13 GMT => 1177534933
|
||||
27: Thu, 19/Apr\2007 16:00:00 GMT => 1176998400
|
||||
28: Fri, 1 Jan 2010 01:01:50 GMT => 1262307710
|
||||
29: Wednesday, 1-Jan-2003 00:00:00 GMT => 1041379200
|
||||
30: , 1-Jan-2003 00:00:00 GMT => 1041379200
|
||||
31: 1-Jan-2003 00:00:00 GMT => 1041379200
|
||||
32: 1-Jan-2003 00:00:00 GMT => 1041379200
|
||||
33: Wed,18-Apr-07 22:50:12 GMT => 1176936612
|
||||
34: WillyWonka , 18-Apr-07 22:50:12 GMT => -1
|
||||
35: WillyWonka , 18-Apr-07 22:50:12 => -1
|
||||
36: WillyWonka , 18-apr-07 22:50:12 => -1
|
||||
37: Mon, 18-Apr-1977 22:50:13 GMT => 230251813
|
||||
38: Mon, 18-Apr-77 22:50:13 GMT => 230251813
|
||||
39: "Sat, 15-Apr-17\"21:01:22\"GMT" => 1492290082
|
||||
40: Partyday, 18- April-07 22:50:12 => -1
|
||||
41: Partyday, 18 - Apri-07 22:50:12 => -1
|
||||
42: Wednes, 1-Januar-2003 00:00:00 GMT => -1
|
||||
43: Sat, 15-Apr-17 21:01:22 => 1492290082
|
||||
44: Sat, 15-Apr-17 21:01:22 GMT-2 => 1492290082
|
||||
45: Sat, 15-Apr-17 21:01:22 GMT BLAH => 1492290082
|
||||
46: Sat, 15-Apr-17 21:01:22 GMT-0400 => 1492290082
|
||||
47: Sat, 15-Apr-17 21:01:22 GMT-0400 (EDT) => 1492290082
|
||||
48: Sat, 15-Apr-17 21:01:22 DST => -1
|
||||
49: Sat, 15-Apr-17 21:01:22 -0400 => 1492304482
|
||||
50: Sat, 15-Apr-17 21:01:22 (hello there) => -1
|
||||
51: Sat, 15-Apr-17 21:01:22 11:22:33 => -1
|
||||
52: Sat, 15-Apr-17 ::00 21:01:22 => -1
|
||||
53: Sat, 15-Apr-17 boink:z 21:01:22 => -1
|
||||
54: Sat, 15-Apr-17 91:22:33 21:01:22 => -1
|
||||
55: Thu Apr 18 22:50:12 2007 GMT => 1176936612
|
||||
56: 22:50:12 Thu Apr 18 2007 GMT => 1176936612
|
||||
57: Thu 22:50:12 Apr 18 2007 GMT => 1176936612
|
||||
58: Thu Apr 22:50:12 18 2007 GMT => 1176936612
|
||||
59: Thu Apr 18 22:50:12 2007 GMT => 1176936612
|
||||
60: Thu Apr 18 2007 22:50:12 GMT => 1176936612
|
||||
61: Thu Apr 18 2007 GMT 22:50:12 => 1176936612
|
||||
62: Sat, 15-Apr-17 21:01:22 GMT => 1492290082
|
||||
63: 15-Sat, Apr-17 21:01:22 GMT => 1492290082
|
||||
64: 15-Sat, Apr 21:01:22 GMT 17 => 1492290082
|
||||
65: 15-Sat, Apr 21:01:22 GMT 2017 => 1492290082
|
||||
66: 15 Apr 21:01:22 2017 => 1492290082
|
||||
67: 15 17 Apr 21:01:22 => 1492290082
|
||||
68: Apr 15 17 21:01:22 => 1492290082
|
||||
69: Apr 15 21:01:22 17 => 1492290082
|
||||
70: 2017 April 15 21:01:22 => -1
|
||||
71: 15 April 2017 21:01:22 => -1
|
||||
72: 98 April 17 21:01:22 => -1
|
||||
73: Thu, 012-Aug-2008 20:49:07 GMT => 1218574147
|
||||
74: Thu, 999999999999-Aug-2007 20:49:07 GMT => -1
|
||||
75: Thu, 12-Aug-2007 20:61:99999999999 GMT => -1
|
||||
76: IAintNoDateFool => -1
|
||||
77: Thu Apr 18 22:50 2007 GMT => 1176936600
|
||||
78: 20110623 12:34:56 => 1308832496
|
||||
79: 20110632 12:34:56 => -1
|
||||
80: 20110623 56:34:56 => -1
|
||||
81: 20111323 12:34:56 => -1
|
||||
82: 20110623 12:34:79 => -1
|
||||
83: Wed, 31 Dec 2008 23:59:60 GMT => 1230768000
|
||||
84: 20110623 12:3 => 1308830580
|
||||
85: 20110623 1:3 => 1308790980
|
||||
86: 20110623 1:30 => 1308792600
|
||||
87: 20110623 12:12:3 => 1308831123
|
||||
88: 20110623 01:12:3 => 1308791523
|
||||
89: 20110623 01:99:30 => -1
|
||||
</stdout>
|
||||
|
||||
# This test case previously tested an overflow case ("2094 Nov 6 =>
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -23,117 +23,141 @@
|
||||
|
||||
#include "memdebug.h"
|
||||
|
||||
static const char * const dates[]={
|
||||
"Sun, 06 Nov 1994 08:49:37 GMT",
|
||||
"Sunday, 06-Nov-94 08:49:37 GMT",
|
||||
"Sun Nov 6 08:49:37 1994",
|
||||
"06 Nov 1994 08:49:37 GMT",
|
||||
"06-Nov-94 08:49:37 GMT",
|
||||
"Nov 6 08:49:37 1994",
|
||||
"06 Nov 1994 08:49:37",
|
||||
"06-Nov-94 08:49:37",
|
||||
"1994 Nov 6 08:49:37",
|
||||
"GMT 08:49:37 06-Nov-94 Sunday",
|
||||
"94 6 Nov 08:49:37",
|
||||
"1994 Nov 6",
|
||||
"06-Nov-94",
|
||||
"Sun Nov 6 94",
|
||||
"1994.Nov.6",
|
||||
"Sun/Nov/6/94/GMT",
|
||||
"Sun, 06 Nov 1994 08:49:37 CET",
|
||||
"06 Nov 1994 08:49:37 EST",
|
||||
"Sun, 12 Sep 2004 15:05:58 -0700",
|
||||
"Sat, 11 Sep 2004 21:32:11 +0200",
|
||||
"20040912 15:05:58 -0700",
|
||||
"20040911 +0200",
|
||||
"Thu, 01-Jan-1970 00:59:59 GMT",
|
||||
"Thu, 01-Jan-1970 01:00:00 GMT",
|
||||
/* "2094 Nov 6", See ../data/test517 for details */
|
||||
"Sat, 15-Apr-17 21:01:22 GMT",
|
||||
"Thu, 19-Apr-2007 16:00:00 GMT",
|
||||
"Wed, 25 Apr 2007 21:02:13 GMT",
|
||||
"Thu, 19/Apr\\2007 16:00:00 GMT",
|
||||
"Fri, 1 Jan 2010 01:01:50 GMT",
|
||||
"Wednesday, 1-Jan-2003 00:00:00 GMT",
|
||||
", 1-Jan-2003 00:00:00 GMT",
|
||||
" 1-Jan-2003 00:00:00 GMT",
|
||||
"1-Jan-2003 00:00:00 GMT",
|
||||
"Wed,18-Apr-07 22:50:12 GMT",
|
||||
"WillyWonka , 18-Apr-07 22:50:12 GMT",
|
||||
"WillyWonka , 18-Apr-07 22:50:12",
|
||||
"WillyWonka , 18-apr-07 22:50:12",
|
||||
"Mon, 18-Apr-1977 22:50:13 GMT",
|
||||
"Mon, 18-Apr-77 22:50:13 GMT",
|
||||
"\"Sat, 15-Apr-17\\\"21:01:22\\\"GMT\"",
|
||||
"Partyday, 18- April-07 22:50:12",
|
||||
"Partyday, 18 - Apri-07 22:50:12",
|
||||
"Wednes, 1-Januar-2003 00:00:00 GMT",
|
||||
"Sat, 15-Apr-17 21:01:22",
|
||||
"Sat, 15-Apr-17 21:01:22 GMT-2",
|
||||
"Sat, 15-Apr-17 21:01:22 GMT BLAH",
|
||||
"Sat, 15-Apr-17 21:01:22 GMT-0400",
|
||||
"Sat, 15-Apr-17 21:01:22 GMT-0400 (EDT)",
|
||||
"Sat, 15-Apr-17 21:01:22 DST",
|
||||
"Sat, 15-Apr-17 21:01:22 -0400",
|
||||
"Sat, 15-Apr-17 21:01:22 (hello there)",
|
||||
"Sat, 15-Apr-17 21:01:22 11:22:33",
|
||||
"Sat, 15-Apr-17 ::00 21:01:22",
|
||||
"Sat, 15-Apr-17 boink:z 21:01:22",
|
||||
"Sat, 15-Apr-17 91:22:33 21:01:22",
|
||||
"Thu Apr 18 22:50:12 2007 GMT",
|
||||
"22:50:12 Thu Apr 18 2007 GMT",
|
||||
"Thu 22:50:12 Apr 18 2007 GMT",
|
||||
"Thu Apr 22:50:12 18 2007 GMT",
|
||||
"Thu Apr 18 22:50:12 2007 GMT",
|
||||
"Thu Apr 18 2007 22:50:12 GMT",
|
||||
"Thu Apr 18 2007 GMT 22:50:12",
|
||||
"Sat, 15-Apr-17 21:01:22 GMT",
|
||||
"15-Sat, Apr-17 21:01:22 GMT",
|
||||
"15-Sat, Apr 21:01:22 GMT 17",
|
||||
"15-Sat, Apr 21:01:22 GMT 2017",
|
||||
"15 Apr 21:01:22 2017",
|
||||
"15 17 Apr 21:01:22",
|
||||
"Apr 15 17 21:01:22",
|
||||
"Apr 15 21:01:22 17",
|
||||
"2017 April 15 21:01:22",
|
||||
"15 April 2017 21:01:22",
|
||||
"98 April 17 21:01:22",
|
||||
"Thu, 012-Aug-2008 20:49:07 GMT",
|
||||
struct dcheck {
|
||||
const char *input;
|
||||
time_t output;
|
||||
};
|
||||
|
||||
struct dcheck dates[] = {
|
||||
{"Sun, 06 Nov 1994 08:49:37 GMT", 784111777 },
|
||||
{"Sunday, 06-Nov-94 08:49:37 GMT", 784111777 },
|
||||
{"Sun Nov 6 08:49:37 1994", 784111777 },
|
||||
{"06 Nov 1994 08:49:37 GMT", 784111777 },
|
||||
{"06-Nov-94 08:49:37 GMT", 784111777 },
|
||||
{"Nov 6 08:49:37 1994", 784111777 },
|
||||
{"06 Nov 1994 08:49:37", 784111777 },
|
||||
{"06-Nov-94 08:49:37", 784111777 },
|
||||
{"1994 Nov 6 08:49:37", 784111777 },
|
||||
{"GMT 08:49:37 06-Nov-94 Sunday", 784111777 },
|
||||
{"94 6 Nov 08:49:37", 784111777 },
|
||||
{"1994 Nov 6", 784080000 },
|
||||
{"06-Nov-94", 784080000 },
|
||||
{"Sun Nov 6 94", 784080000 },
|
||||
{"1994.Nov.6", 784080000 },
|
||||
{"Sun/Nov/6/94/GMT", 784080000 },
|
||||
{"Sun, 06 Nov 1994 08:49:37 CET", 784108177 },
|
||||
{"06 Nov 1994 08:49:37 EST", 784129777 },
|
||||
{"Sun, 12 Sep 2004 15:05:58 -0700", 1095026758 },
|
||||
{"Sat, 11 Sep 2004 21:32:11 +0200", 1094931131 },
|
||||
{"20040912 15:05:58 -0700", 1095026758 },
|
||||
{"20040911 +0200", 1094853600 },
|
||||
{"Thu, 01-Jan-1970 00:59:59 GMT", 3599 },
|
||||
{"Thu, 01-Jan-1970 01:00:00 GMT", 3600 },
|
||||
{"Sat, 15-Apr-17 21:01:22 GMT", 1492290082 },
|
||||
{"Thu, 19-Apr-2007 16:00:00 GMT", 1176998400 },
|
||||
{"Wed, 25 Apr 2007 21:02:13 GMT", 1177534933 },
|
||||
{"Thu, 19/Apr\\2007 16:00:00 GMT", 1176998400 },
|
||||
{"Fri, 1 Jan 2010 01:01:50 GMT", 1262307710 },
|
||||
{"Wednesday, 1-Jan-2003 00:00:00 GMT", 1041379200 },
|
||||
{", 1-Jan-2003 00:00:00 GMT", 1041379200 },
|
||||
{"1-Jan-2003 00:00:00 GMT", 1041379200 },
|
||||
{"1-Jan-2003 00:00:00 GMT", 1041379200 },
|
||||
{"Wed,18-Apr-07 22:50:12 GMT", 1176936612 },
|
||||
{"WillyWonka , 18-Apr-07 22:50:12 GMT", -1 },
|
||||
{"WillyWonka , 18-Apr-07 22:50:12", -1 },
|
||||
{"WillyWonka , 18-apr-07 22:50:12", -1 },
|
||||
{"Mon, 18-Apr-1977 22:50:13 GMT", 230251813 },
|
||||
{"Mon, 18-Apr-77 22:50:13 GMT", 230251813 },
|
||||
{"Sat, 15-Apr-17\"21:01:22\"GMT", 1492290082 },
|
||||
{"Partyday, 18- April-07 22:50:12", -1 },
|
||||
{"Partyday, 18 - Apri-07 22:50:12", -1 },
|
||||
{"Wednes, 1-Januar-2003 00:00:00 GMT", -1 },
|
||||
{"Sat, 15-Apr-17 21:01:22", 1492290082 },
|
||||
{"Sat, 15-Apr-17 21:01:22 GMT-2", 1492290082 },
|
||||
{"Sat, 15-Apr-17 21:01:22 GMT BLAH", 1492290082 },
|
||||
{"Sat, 15-Apr-17 21:01:22 GMT-0400", 1492290082 },
|
||||
{"Sat, 15-Apr-17 21:01:22 GMT-0400 (EDT)", 1492290082 },
|
||||
{"Sat, 15-Apr-17 21:01:22 DST", -1 },
|
||||
{"Sat, 15-Apr-17 21:01:22 -0400", 1492304482 },
|
||||
{"Sat, 15-Apr-17 21:01:22 (hello there)", -1 },
|
||||
{"Sat, 15-Apr-17 21:01:22 11:22:33", -1 },
|
||||
{"Sat, 15-Apr-17 ::00 21:01:22", -1 },
|
||||
{"Sat, 15-Apr-17 boink:z 21:01:22", -1 },
|
||||
{"Sat, 15-Apr-17 91:22:33 21:01:22", -1 },
|
||||
{"Thu Apr 18 22:50:12 2007 GMT", 1176936612 },
|
||||
{"22:50:12 Thu Apr 18 2007 GMT", 1176936612 },
|
||||
{"Thu 22:50:12 Apr 18 2007 GMT", 1176936612 },
|
||||
{"Thu Apr 22:50:12 18 2007 GMT", 1176936612 },
|
||||
{"Thu Apr 18 22:50:12 2007 GMT", 1176936612 },
|
||||
{"Thu Apr 18 2007 22:50:12 GMT", 1176936612 },
|
||||
{"Thu Apr 18 2007 GMT 22:50:12", 1176936612 },
|
||||
{"Sat, 15-Apr-17 21:01:22 GMT", 1492290082 },
|
||||
{"15-Sat, Apr-17 21:01:22 GMT", 1492290082 },
|
||||
{"15-Sat, Apr 21:01:22 GMT 17", 1492290082 },
|
||||
{"15-Sat, Apr 21:01:22 GMT 2017", 1492290082 },
|
||||
{"15 Apr 21:01:22 2017", 1492290082 },
|
||||
{"15 17 Apr 21:01:22", 1492290082 },
|
||||
{"Apr 15 17 21:01:22", 1492290082 },
|
||||
{"Apr 15 21:01:22 17", 1492290082 },
|
||||
{"2017 April 15 21:01:22", -1 },
|
||||
{"15 April 2017 21:01:22", -1 },
|
||||
{"98 April 17 21:01:22", -1 },
|
||||
{"Thu, 012-Aug-2008 20:49:07 GMT", 1218574147 },
|
||||
{"Thu, 999999999999-Aug-2007 20:49:07 GMT", -1 },
|
||||
{"Thu, 12-Aug-2007 20:61:99999999999 GMT", -1 },
|
||||
{"IAintNoDateFool", -1 },
|
||||
{"Thu Apr 18 22:50 2007 GMT", 1176936600 },
|
||||
{"20110623 12:34:56", 1308832496 },
|
||||
{"20110632 12:34:56", -1 },
|
||||
{"20110623 56:34:56", -1 },
|
||||
{"20111323 12:34:56", -1 },
|
||||
{"20110623 12:34:79", -1 },
|
||||
{"Wed, 31 Dec 2008 23:59:60 GMT", 1230768000 },
|
||||
{"20110623 12:3", 1308830580 },
|
||||
{"20110623 1:3", 1308790980 },
|
||||
{"20110623 1:30", 1308792600 },
|
||||
{"20110623 12:12:3", 1308831123 },
|
||||
{"20110623 01:12:3", 1308791523 },
|
||||
{"20110623 01:99:30", -1 },
|
||||
{"Thu, 01-Jan-1970 00:00:00 GMT", 0 },
|
||||
{"Thu, 31-Dec-1969 23:59:58 GMT", -2 },
|
||||
{"Thu, 31-Dec-1969 23:59:59 GMT", 0 }, /* avoids -1 ! */
|
||||
#if SIZEOF_TIME_T > 4
|
||||
{"Sun, 06 Nov 2044 08:49:37 GMT", 2362034977 },
|
||||
{"Sun, 06 Nov 3144 08:49:37 GMT", 37074617377 },
|
||||
#ifndef HAVE_TIME_T_UNSIGNED
|
||||
#if 0
|
||||
/* leaving out these strings since they differ between 32 and 64 bit
|
||||
archs and the test suite has no good way to support two different outputs
|
||||
like that */
|
||||
"Thu, 12-Aug-31841 20:49:07 GMT",
|
||||
"Thu, 12-Aug-9999999999 20:49:07 GMT",
|
||||
/* causes warning on MSVC */
|
||||
{"Sun, 06 Nov 1900 08:49:37 GMT", -2182259423 },
|
||||
#endif
|
||||
"Thu, 999999999999-Aug-2007 20:49:07 GMT",
|
||||
"Thu, 12-Aug-2007 20:61:99999999999 GMT",
|
||||
"IAintNoDateFool",
|
||||
"Thu Apr 18 22:50 2007 GMT", /* without seconds */
|
||||
"20110623 12:34:56",
|
||||
"20110632 12:34:56",
|
||||
"20110623 56:34:56",
|
||||
"20111323 12:34:56",
|
||||
"20110623 12:34:79",
|
||||
"Wed, 31 Dec 2008 23:59:60 GMT", /* leap second */
|
||||
"20110623 12:3",
|
||||
"20110623 1:3",
|
||||
"20110623 1:30",
|
||||
"20110623 12:12:3",
|
||||
"20110623 01:12:3",
|
||||
"20110623 01:99:30",
|
||||
NULL
|
||||
{"Sun, 06 Nov 1800 08:49:37 GMT", -5337933023 },
|
||||
{"Thu, 01-Jan-1583 00:00:00 GMT", -12212553600 },
|
||||
#endif
|
||||
{"Thu, 01-Jan-1499 00:00:00 GMT", -1 },
|
||||
#else
|
||||
{"Sun, 06 Nov 2044 08:49:37 GMT", -1 },
|
||||
#endif
|
||||
#ifndef HAVE_TIME_T_UNSIGNED
|
||||
{"Sun, 06 Nov 1968 08:49:37 GMT", -36342623 },
|
||||
#endif
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
int test(char *URL)
|
||||
{
|
||||
int i;
|
||||
int error = 0;
|
||||
|
||||
(void)URL; /* not used */
|
||||
|
||||
for(i = 0; dates[i]; i++) {
|
||||
printf("%d: %s => %ld\n", i, dates[i], (long)curl_getdate(dates[i], NULL));
|
||||
for(i = 0; dates[i].input; i++) {
|
||||
time_t out = curl_getdate(dates[i].input, NULL);
|
||||
if(out != dates[i].output) {
|
||||
printf("WRONGLY %s => %ld (instead of %ld)\n",
|
||||
dates[i].input, out, dates[i].output);
|
||||
error++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user