Coverage Report

Created: 2025-08-24 06:12

/src/curl/lib/parsedate.c
Line
Count
Source (jump to first uncovered line)
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
 *
10
 * This software is licensed as described in the file COPYING, which
11
 * you should have received as part of this distribution. The terms
12
 * are also available at https://curl.se/docs/copyright.html.
13
 *
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
 * copies of the Software, and permit persons to whom the Software is
16
 * furnished to do so, under the terms of the COPYING file.
17
 *
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
 * KIND, either express or implied.
20
 *
21
 * SPDX-License-Identifier: curl
22
 *
23
 ***************************************************************************/
24
/*
25
  A brief summary of the date string formats this parser groks:
26
27
  RFC 2616 3.3.1
28
29
  Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
30
  Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
31
  Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format
32
33
  we support dates without week day name:
34
35
  06 Nov 1994 08:49:37 GMT
36
  06-Nov-94 08:49:37 GMT
37
  Nov  6 08:49:37 1994
38
39
  without the time zone:
40
41
  06 Nov 1994 08:49:37
42
  06-Nov-94 08:49:37
43
44
  weird order:
45
46
  1994 Nov 6 08:49:37  (GNU date fails)
47
  GMT 08:49:37 06-Nov-94 Sunday
48
  94 6 Nov 08:49:37    (GNU date fails)
49
50
  time left out:
51
52
  1994 Nov 6
53
  06-Nov-94
54
  Sun Nov 6 94
55
56
  unusual separators:
57
58
  1994.Nov.6
59
  Sun/Nov/6/94/GMT
60
61
  commonly used time zone names:
62
63
  Sun, 06 Nov 1994 08:49:37 CET
64
  06 Nov 1994 08:49:37 EST
65
66
  time zones specified using RFC822 style:
67
68
  Sun, 12 Sep 2004 15:05:58 -0700
69
  Sat, 11 Sep 2004 21:32:11 +0200
70
71
  compact numerical date strings:
72
73
  20040912 15:05:58 -0700
74
  20040911 +0200
75
76
*/
77
78
#include "curl_setup.h"
79
80
#include <limits.h>
81
82
#include <curl/curl.h>
83
#include "curlx/warnless.h"
84
#include "parsedate.h"
85
#include "curlx/strparse.h"
86
87
/*
88
 * parsedate()
89
 *
90
 * Returns:
91
 *
92
 * PARSEDATE_OK     - a fine conversion
93
 * PARSEDATE_FAIL   - failed to convert
94
 * PARSEDATE_LATER  - time overflow at the far end of time_t
95
 * PARSEDATE_SOONER - time underflow at the low end of time_t
96
 */
97
98
static int parsedate(const char *date, time_t *output);
99
100
19.8k
#define PARSEDATE_OK     0
101
83.9k
#define PARSEDATE_FAIL   -1
102
0
#define PARSEDATE_LATER  1
103
#if defined(HAVE_TIME_T_UNSIGNED) || (SIZEOF_TIME_T < 5)
104
#define PARSEDATE_SOONER 2
105
#endif
106
107
#if !defined(CURL_DISABLE_PARSEDATE) || !defined(CURL_DISABLE_FTP) || \
108
  !defined(CURL_DISABLE_FILE) || defined(USE_GNUTLS)
109
/* These names are also used by FTP and FILE code */
110
const char * const Curl_wkday[] =
111
{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
112
const char * const Curl_month[]=
113
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
114
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
115
#endif
116
117
#ifndef CURL_DISABLE_PARSEDATE
118
static const char * const weekday[] =
119
{ "Monday", "Tuesday", "Wednesday", "Thursday",
120
  "Friday", "Saturday", "Sunday" };
121
122
struct tzinfo {
123
  char name[5];
124
  int offset; /* +/- in minutes */
125
};
126
127
/* Here's a bunch of frequently used time zone names. These were supported
128
   by the old getdate parser. */
129
#define tDAYZONE -60       /* offset for daylight savings time */
130
static const struct tzinfo tz[]= {
131
  {"GMT", 0},              /* Greenwich Mean */
132
  {"UT",  0},              /* Universal Time */
133
  {"UTC", 0},              /* Universal (Coordinated) */
134
  {"WET", 0},              /* Western European */
135
  {"BST", 0 tDAYZONE},     /* British Summer */
136
  {"WAT", 60},             /* West Africa */
137
  {"AST", 240},            /* Atlantic Standard */
138
  {"ADT", 240 tDAYZONE},   /* Atlantic Daylight */
139
  {"EST", 300},            /* Eastern Standard */
140
  {"EDT", 300 tDAYZONE},   /* Eastern Daylight */
141
  {"CST", 360},            /* Central Standard */
142
  {"CDT", 360 tDAYZONE},   /* Central Daylight */
143
  {"MST", 420},            /* Mountain Standard */
144
  {"MDT", 420 tDAYZONE},   /* Mountain Daylight */
145
  {"PST", 480},            /* Pacific Standard */
146
  {"PDT", 480 tDAYZONE},   /* Pacific Daylight */
147
  {"YST", 540},            /* Yukon Standard */
148
  {"YDT", 540 tDAYZONE},   /* Yukon Daylight */
149
  {"HST", 600},            /* Hawaii Standard */
150
  {"HDT", 600 tDAYZONE},   /* Hawaii Daylight */
151
  {"CAT", 600},            /* Central Alaska */
152
  {"AHST", 600},           /* Alaska-Hawaii Standard */
153
  {"NT",  660},            /* Nome */ /* spellchecker:disable-line */
154
  {"IDLW", 720},           /* International Date Line West */
155
  {"CET", -60},            /* Central European */
156
  {"MET", -60},            /* Middle European */
157
  {"MEWT", -60},           /* Middle European Winter */
158
  {"MEST", -60 tDAYZONE},  /* Middle European Summer */
159
  {"CEST", -60 tDAYZONE},  /* Central European Summer */
160
  {"MESZ", -60 tDAYZONE},  /* Middle European Summer */
161
  {"FWT", -60},            /* French Winter */
162
  {"FST", -60 tDAYZONE},   /* French Summer */
163
  {"EET", -120},           /* Eastern Europe, USSR Zone 1 */
164
  {"WAST", -420}, /* spellchecker:disable-line */
165
                           /* West Australian Standard */
166
  {"WADT", -420 tDAYZONE}, /* West Australian Daylight */
167
  {"CCT", -480},           /* China Coast, USSR Zone 7 */
168
  {"JST", -540},           /* Japan Standard, USSR Zone 8 */
169
  {"EAST", -600},          /* Eastern Australian Standard */
170
  {"EADT", -600 tDAYZONE}, /* Eastern Australian Daylight */
171
  {"GST", -600},           /* Guam Standard, USSR Zone 9 */
172
  {"NZT", -720},           /* New Zealand */
173
  {"NZST", -720},          /* New Zealand Standard */
174
  {"NZDT", -720 tDAYZONE}, /* New Zealand Daylight */
175
  {"IDLE", -720},          /* International Date Line East */
176
  /* Next up: Military timezone names. RFC822 allowed these, but (as noted in
177
     RFC 1123) had their signs wrong. Here we use the correct signs to match
178
     actual military usage.
179
   */
180
  {"A",  1 * 60},         /* Alpha */
181
  {"B",  2 * 60},         /* Bravo */
182
  {"C",  3 * 60},         /* Charlie */
183
  {"D",  4 * 60},         /* Delta */
184
  {"E",  5 * 60},         /* Echo */
185
  {"F",  6 * 60},         /* Foxtrot */
186
  {"G",  7 * 60},         /* Golf */
187
  {"H",  8 * 60},         /* Hotel */
188
  {"I",  9 * 60},         /* India */
189
  /* "J", Juliet is not used as a timezone, to indicate the observer's local
190
     time */
191
  {"K", 10 * 60},         /* Kilo */
192
  {"L", 11 * 60},         /* Lima */
193
  {"M", 12 * 60},         /* Mike */
194
  {"N",  -1 * 60},         /* November */
195
  {"O",  -2 * 60},         /* Oscar */
196
  {"P",  -3 * 60},         /* Papa */
197
  {"Q",  -4 * 60},         /* Quebec */
198
  {"R",  -5 * 60},         /* Romeo */
199
  {"S",  -6 * 60},         /* Sierra */
200
  {"T",  -7 * 60},         /* Tango */
201
  {"U",  -8 * 60},         /* Uniform */
202
  {"V",  -9 * 60},         /* Victor */
203
  {"W", -10 * 60},         /* Whiskey */
204
  {"X", -11 * 60},         /* X-ray */
205
  {"Y", -12 * 60},         /* Yankee */
206
  {"Z", 0},                /* Zulu, zero meridian, a.k.a. UTC */
207
};
208
209
/* returns:
210
   -1 no day
211
   0 monday - 6 sunday
212
*/
213
214
static int checkday(const char *check, size_t len)
215
87.8k
{
216
87.8k
  int i;
217
87.8k
  const char * const *what;
218
87.8k
  if(len > 3)
219
10.0k
    what = &weekday[0];
220
77.8k
  else if(len == 3)
221
32.1k
    what = &Curl_wkday[0];
222
45.7k
  else
223
45.7k
    return -1; /* too short */
224
314k
  for(i = 0; i < 7; i++) {
225
279k
    size_t ilen = strlen(what[0]);
226
279k
    if((ilen == len) &&
227
279k
       curl_strnequal(check, what[0], len))
228
6.40k
      return i;
229
272k
    what++;
230
272k
  }
231
35.7k
  return -1;
232
42.1k
}
233
234
static int checkmonth(const char *check, size_t len)
235
74.5k
{
236
74.5k
  int i;
237
74.5k
  const char * const *what = &Curl_month[0];
238
74.5k
  if(len != 3)
239
47.9k
    return -1; /* not a month */
240
241
194k
  for(i = 0; i < 12; i++) {
242
189k
    if(curl_strnequal(check, what[0], 3))
243
21.5k
      return i;
244
168k
    what++;
245
168k
  }
246
4.97k
  return -1; /* return the offset or -1, no real offset is -1 */
247
26.5k
}
248
249
/* return the time zone offset between GMT and the input one, in number
250
   of seconds or -1 if the timezone was not found/legal */
251
252
static int checktz(const char *check, size_t len)
253
54.1k
{
254
54.1k
  unsigned int i;
255
54.1k
  const struct tzinfo *what = tz;
256
54.1k
  if(len > 4) /* longer than any valid timezone */
257
6.33k
    return -1;
258
259
2.71M
  for(i = 0; i < CURL_ARRAYSIZE(tz); i++) {
260
2.70M
    size_t ilen = strlen(what->name);
261
2.70M
    if((ilen == len) &&
262
2.70M
       curl_strnequal(check, what->name, len))
263
39.0k
      return what->offset*60;
264
2.66M
    what++;
265
2.66M
  }
266
8.74k
  return -1;
267
47.7k
}
268
269
static void skip(const char **date)
270
268k
{
271
  /* skip everything that are not letters or digits */
272
791k
  while(**date && !ISALNUM(**date))
273
523k
    (*date)++;
274
268k
}
275
276
enum assume {
277
  DATE_MDAY,
278
  DATE_YEAR,
279
  DATE_TIME
280
};
281
282
/*
283
 * time2epoch: time stamp to seconds since epoch in GMT time zone. Similar to
284
 * mktime but for GMT only.
285
 */
286
static time_t time2epoch(int sec, int min, int hour,
287
                         int mday, int mon, int year)
288
9.94k
{
289
9.94k
  static const int month_days_cumulative [12] =
290
9.94k
    { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
291
9.94k
  int leap_days = year - (mon <= 1);
292
9.94k
  leap_days = ((leap_days / 4) - (leap_days / 100) + (leap_days / 400)
293
9.94k
               - (1969 / 4) + (1969 / 100) - (1969 / 400));
294
9.94k
  return ((((time_t) (year - 1970) * 365
295
9.94k
            + leap_days + month_days_cumulative[mon] + mday - 1) * 24
296
9.94k
           + hour) * 60 + min) * 60 + sec;
297
9.94k
}
298
299
/* Returns the value of a single-digit or two-digit decimal number, return
300
   then pointer to after the number. The 'date' pointer is known to point to a
301
   digit. */
302
static int oneortwodigit(const char *date, const char **endp)
303
163k
{
304
163k
  int num = date[0] - '0';
305
163k
  if(ISDIGIT(date[1])) {
306
81.3k
    *endp = &date[2];
307
81.3k
    return num*10 + (date[1] - '0');
308
81.3k
  }
309
82.6k
  *endp = &date[1];
310
82.6k
  return num;
311
163k
}
312
313
314
/* HH:MM:SS or HH:MM and accept single-digits too */
315
static bool match_time(const char *date,
316
                       int *h, int *m, int *s, char **endp)
317
133k
{
318
133k
  const char *p;
319
133k
  int hh, mm, ss = 0;
320
133k
  hh = oneortwodigit(date, &p);
321
133k
  if((hh < 24) && (*p == ':') && ISDIGIT(p[1])) {
322
22.6k
    mm = oneortwodigit(&p[1], &p);
323
22.6k
    if(mm < 60) {
324
18.8k
      if((*p == ':') && ISDIGIT(p[1])) {
325
8.00k
        ss = oneortwodigit(&p[1], &p);
326
8.00k
        if(ss <= 60) {
327
          /* valid HH:MM:SS */
328
5.62k
          goto match;
329
5.62k
        }
330
8.00k
      }
331
10.8k
      else {
332
        /* valid HH:MM */
333
10.8k
        goto match;
334
10.8k
      }
335
18.8k
    }
336
22.6k
  }
337
116k
  return FALSE; /* not a time string */
338
16.4k
match:
339
16.4k
  *h = hh;
340
16.4k
  *m = mm;
341
16.4k
  *s = ss;
342
16.4k
  *endp = (char *)CURL_UNCONST(p);
343
16.4k
  return TRUE;
344
133k
}
345
346
/*
347
 * parsedate()
348
 *
349
 * Returns:
350
 *
351
 * PARSEDATE_OK     - a fine conversion
352
 * PARSEDATE_FAIL   - failed to convert
353
 * PARSEDATE_LATER  - time overflow at the far end of time_t
354
 * PARSEDATE_SOONER - time underflow at the low end of time_t
355
 */
356
357
/* Wednesday is the longest name this parser knows about */
358
336k
#define NAME_LEN 12
359
360
static int parsedate(const char *date, time_t *output)
361
93.9k
{
362
93.9k
  time_t t = 0;
363
93.9k
  int wdaynum = -1;  /* day of the week number, 0-6 (mon-sun) */
364
93.9k
  int monnum = -1;   /* month of the year number, 0-11 */
365
93.9k
  int mdaynum = -1; /* day of month, 1 - 31 */
366
93.9k
  int hournum = -1;
367
93.9k
  int minnum = -1;
368
93.9k
  int secnum = -1;
369
93.9k
  int yearnum = -1;
370
93.9k
  int tzoff = -1;
371
93.9k
  enum assume dignext = DATE_MDAY;
372
93.9k
  const char *indate = date; /* save the original pointer */
373
93.9k
  int part = 0; /* max 6 parts */
374
375
309k
  while(*date && (part < 6)) {
376
268k
    bool found = FALSE;
377
378
268k
    skip(&date);
379
380
268k
    if(ISALPHA(*date)) {
381
      /* a name coming up */
382
97.5k
      size_t len = 0;
383
97.5k
      const char *p = date;
384
335k
      while(ISALPHA(*p) && (len < NAME_LEN)) {
385
237k
        p++;
386
237k
        len++;
387
237k
      }
388
389
97.5k
      if(len != NAME_LEN) {
390
96.1k
        if(wdaynum == -1) {
391
87.8k
          wdaynum = checkday(date, len);
392
87.8k
          if(wdaynum != -1)
393
6.40k
            found = TRUE;
394
87.8k
        }
395
96.1k
        if(!found && (monnum == -1)) {
396
74.5k
          monnum = checkmonth(date, len);
397
74.5k
          if(monnum != -1)
398
21.5k
            found = TRUE;
399
74.5k
        }
400
401
96.1k
        if(!found && (tzoff == -1)) {
402
          /* this just must be a time zone string */
403
54.1k
          tzoff = checktz(date, len);
404
54.1k
          if(tzoff != -1)
405
39.0k
            found = TRUE;
406
54.1k
        }
407
96.1k
      }
408
97.5k
      if(!found)
409
30.5k
        return PARSEDATE_FAIL; /* bad string */
410
411
67.0k
      date += len;
412
67.0k
    }
413
170k
    else if(ISDIGIT(*date)) {
414
      /* a digit */
415
144k
      unsigned int val;
416
144k
      char *end;
417
144k
      if((secnum == -1) &&
418
144k
         match_time(date, &hournum, &minnum, &secnum, &end)) {
419
        /* time stamp */
420
16.4k
        date = end;
421
16.4k
      }
422
128k
      else {
423
128k
        curl_off_t lval;
424
128k
        int num_digits = 0;
425
128k
        const char *p = date;
426
128k
        if(curlx_str_number(&p, &lval, 99999999))
427
1.68k
          return PARSEDATE_FAIL;
428
429
        /* we know num_digits cannot be larger than 8 */
430
126k
        num_digits = (int)(p - date);
431
126k
        val = (unsigned int)lval;
432
433
126k
        if((tzoff == -1) &&
434
126k
           (num_digits == 4) &&
435
126k
           (val <= 1400) &&
436
126k
           (indate < date) &&
437
126k
           ((date[-1] == '+' || date[-1] == '-'))) {
438
          /* four digits and a value less than or equal to 1400 (to take into
439
             account all sorts of funny time zone diffs) and it is preceded
440
             with a plus or minus. This is a time zone indication. 1400 is
441
             picked since +1300 is frequently used and +1400 is mentioned as
442
             an edge number in the document "ISO C 200X Proposal: Timezone
443
             Functions" at http://david.tribble.com/text/c0xtimezone.html If
444
             anyone has a more authoritative source for the exact maximum time
445
             zone offsets, please speak up! */
446
4.66k
          found = TRUE;
447
4.66k
          tzoff = (val/100 * 60 + val%100)*60;
448
449
          /* the + and - prefix indicates the local time compared to GMT,
450
             this we need their reversed math to get what we want */
451
4.66k
          tzoff = date[-1]=='+' ? -tzoff : tzoff;
452
4.66k
        }
453
454
121k
        else if((num_digits == 8) &&
455
121k
                (yearnum == -1) &&
456
121k
                (monnum == -1) &&
457
121k
                (mdaynum == -1)) {
458
          /* 8 digits, no year, month or day yet. This is YYYYMMDD */
459
6.88k
          found = TRUE;
460
6.88k
          yearnum = val/10000;
461
6.88k
          monnum = (val%10000)/100-1; /* month is 0 - 11 */
462
6.88k
          mdaynum = val%100;
463
6.88k
        }
464
465
126k
        if(!found && (dignext == DATE_MDAY) && (mdaynum == -1)) {
466
79.5k
          if((val > 0) && (val < 32)) {
467
44.6k
            mdaynum = val;
468
44.6k
            found = TRUE;
469
44.6k
          }
470
79.5k
          dignext = DATE_YEAR;
471
79.5k
        }
472
473
126k
        if(!found && (dignext == DATE_YEAR) && (yearnum == -1)) {
474
49.9k
          yearnum = val;
475
49.9k
          found = TRUE;
476
49.9k
          if(yearnum < 100) {
477
30.6k
            if(yearnum > 70)
478
4.39k
              yearnum += 1900;
479
26.2k
            else
480
26.2k
              yearnum += 2000;
481
30.6k
          }
482
49.9k
          if(mdaynum == -1)
483
26.7k
            dignext = DATE_MDAY;
484
49.9k
        }
485
486
126k
        if(!found)
487
20.1k
          return PARSEDATE_FAIL;
488
489
106k
        date = p;
490
106k
      }
491
144k
    }
492
493
215k
    part++;
494
215k
  }
495
496
41.5k
  if(-1 == secnum)
497
31.2k
    secnum = minnum = hournum = 0; /* no time, make it zero */
498
499
41.5k
  if((-1 == mdaynum) ||
500
41.5k
     (-1 == monnum) ||
501
41.5k
     (-1 == yearnum))
502
    /* lacks vital info, fail */
503
26.6k
    return PARSEDATE_FAIL;
504
505
#ifdef HAVE_TIME_T_UNSIGNED
506
  if(yearnum < 1970) {
507
    /* only positive numbers cannot return earlier */
508
    *output = TIME_T_MIN;
509
    return PARSEDATE_SOONER;
510
  }
511
#endif
512
513
#if (SIZEOF_TIME_T < 5)
514
515
#ifdef HAVE_TIME_T_UNSIGNED
516
  /* an unsigned 32-bit time_t can only hold dates to 2106 */
517
  if(yearnum > 2105) {
518
    *output = TIME_T_MAX;
519
    return PARSEDATE_LATER;
520
  }
521
#else
522
  /* a signed 32-bit time_t can only hold dates to the beginning of 2038 */
523
  if(yearnum > 2037) {
524
    *output = TIME_T_MAX;
525
    return PARSEDATE_LATER;
526
  }
527
  if(yearnum < 1903) {
528
    *output = TIME_T_MIN;
529
    return PARSEDATE_SOONER;
530
  }
531
#endif
532
533
#else
534
  /* The Gregorian calendar was introduced 1582 */
535
14.9k
  if(yearnum < 1583)
536
2.18k
    return PARSEDATE_FAIL;
537
12.7k
#endif
538
539
12.7k
  if((mdaynum > 31) || (monnum > 11) ||
540
12.7k
     (hournum > 23) || (minnum > 59) || (secnum > 60))
541
2.80k
    return PARSEDATE_FAIL; /* clearly an illegal date */
542
543
  /* time2epoch() returns a time_t. time_t is often 32 bits, sometimes even on
544
     architectures that feature a 64 bits 'long' but ultimately time_t is the
545
     correct data type to use.
546
  */
547
9.94k
  t = time2epoch(secnum, minnum, hournum, mdaynum, monnum, yearnum);
548
549
  /* Add the time zone diff between local time zone and GMT. */
550
9.94k
  if(tzoff == -1)
551
4.90k
    tzoff = 0;
552
553
9.94k
  if((tzoff > 0) && (t > (time_t)(TIME_T_MAX - tzoff))) {
554
0
    *output = TIME_T_MAX;
555
0
    return PARSEDATE_LATER; /* time_t overflow */
556
0
  }
557
558
9.94k
  t += tzoff;
559
560
9.94k
  *output = t;
561
562
9.94k
  return PARSEDATE_OK;
563
9.94k
}
564
#else
565
/* disabled */
566
static int parsedate(const char *date, time_t *output)
567
{
568
  (void)date;
569
  *output = 0;
570
  return PARSEDATE_OK; /* a lie */
571
}
572
#endif
573
574
time_t curl_getdate(const char *p, const time_t *now)
575
0
{
576
0
  time_t parsed = -1;
577
0
  int rc = parsedate(p, &parsed);
578
0
  (void)now; /* legacy argument from the past that we ignore */
579
580
0
  if(rc == PARSEDATE_OK) {
581
0
    if(parsed == (time_t)-1)
582
      /* avoid returning -1 for a working scenario */
583
0
      parsed++;
584
0
    return parsed;
585
0
  }
586
  /* everything else is fail */
587
0
  return -1;
588
0
}
589
590
/* Curl_getdate_capped() differs from curl_getdate() in that this will return
591
   TIME_T_MAX in case the parsed time value was too big, instead of an
592
   error. */
593
594
time_t Curl_getdate_capped(const char *p)
595
93.9k
{
596
93.9k
  time_t parsed = -1;
597
93.9k
  int rc = parsedate(p, &parsed);
598
599
93.9k
  switch(rc) {
600
9.94k
  case PARSEDATE_OK:
601
9.94k
    if(parsed == (time_t)-1)
602
      /* avoid returning -1 for a working scenario */
603
365
      parsed++;
604
9.94k
    return parsed;
605
0
  case PARSEDATE_LATER:
606
    /* this returns the maximum time value */
607
0
    return parsed;
608
83.9k
  default:
609
83.9k
    return -1; /* everything else is fail */
610
93.9k
  }
611
  /* UNREACHABLE */
612
93.9k
}
613
614
/*
615
 * Curl_gmtime() is a gmtime() replacement for portability. Do not use the
616
 * gmtime_r() or gmtime() functions anywhere else but here.
617
 *
618
 */
619
620
CURLcode Curl_gmtime(time_t intime, struct tm *store)
621
15.6k
{
622
15.6k
  const struct tm *tm;
623
15.6k
#ifdef HAVE_GMTIME_R
624
  /* thread-safe version */
625
15.6k
  tm = (struct tm *)gmtime_r(&intime, store);
626
#else
627
  /* !checksrc! disable BANNEDFUNC 1 */
628
  tm = gmtime(&intime);
629
  if(tm)
630
    *store = *tm; /* copy the pointed struct to the local copy */
631
#endif
632
633
15.6k
  if(!tm)
634
59
    return CURLE_BAD_FUNCTION_ARGUMENT;
635
15.6k
  return CURLE_OK;
636
15.6k
}