Coverage Report

Created: 2023-03-26 06:28

/src/httpd/srclib/apr/util-misc/apr_date.c
Line
Count
Source (jump to first uncovered line)
1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
 * contributor license agreements.  See the NOTICE file distributed with
3
 * this work for additional information regarding copyright ownership.
4
 * The ASF licenses this file to You under the Apache License, Version 2.0
5
 * (the "License"); you may not use this file except in compliance with
6
 * the License.  You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
/*
18
 * apr_date.c: date parsing utility routines
19
 *     These routines are (hopefully) platform independent.
20
 *
21
 * 27 Oct 1996  Roy Fielding
22
 *     Extracted (with many modifications) from mod_proxy.c and
23
 *     tested with over 50,000 randomly chosen valid date strings
24
 *     and several hundred variations of invalid date strings.
25
 *
26
 */
27
28
#include "apr.h"
29
#include "apr_lib.h"
30
31
#define APR_WANT_STRFUNC
32
#include "apr_want.h"
33
34
#if APR_HAVE_STDLIB_H
35
#include <stdlib.h>
36
#endif
37
38
#if APR_HAVE_CTYPE_H
39
#include <ctype.h>
40
#endif
41
42
#include "apr_date.h"
43
44
/*
45
 * Compare a string to a mask
46
 * Mask characters (arbitrary maximum is 256 characters, just in case):
47
 *   @ - uppercase letter
48
 *   $ - lowercase letter
49
 *   & - hex digit
50
 *   # - digit
51
 *   ~ - digit or space
52
 *   * - swallow remaining characters
53
 *  <x> - exact match for any other character
54
 */
55
APR_DECLARE(int) apr_date_checkmask(const char *data, const char *mask)
56
0
{
57
0
    int i;
58
0
    char d;
59
60
0
    for (i = 0; i < 256; i++) {
61
0
        d = data[i];
62
0
        switch (mask[i]) {
63
0
        case '\0':
64
0
            return (d == '\0');
65
66
0
        case '*':
67
0
            return 1;
68
69
0
        case '@':
70
0
            if (!apr_isupper(d))
71
0
                return 0;
72
0
            break;
73
0
        case '$':
74
0
            if (!apr_islower(d))
75
0
                return 0;
76
0
            break;
77
0
        case '#':
78
0
            if (!apr_isdigit(d))
79
0
                return 0;
80
0
            break;
81
0
        case '&':
82
0
            if (!apr_isxdigit(d))
83
0
                return 0;
84
0
            break;
85
0
        case '~':
86
0
            if ((d != ' ') && !apr_isdigit(d))
87
0
                return 0;
88
0
            break;
89
0
        default:
90
0
            if (mask[i] != d)
91
0
                return 0;
92
0
            break;
93
0
        }
94
0
    }
95
0
    return 0;          /* We only get here if mask is corrupted (exceeds 256) */
96
0
}
97
98
/*
99
 * Parses an HTTP date in one of three standard forms:
100
 *
101
 *     Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
102
 *     Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
103
 *     Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format
104
 *
105
 * and returns the apr_time_t number of microseconds since 1 Jan 1970 GMT,
106
 * or APR_DATE_BAD if this would be out of range or if the date is invalid.
107
 *
108
 * The restricted HTTP syntax is
109
 *
110
 *     HTTP-date    = rfc1123-date | rfc850-date | asctime-date
111
 *
112
 *     rfc1123-date = wkday "," SP date1 SP time SP "GMT"
113
 *     rfc850-date  = weekday "," SP date2 SP time SP "GMT"
114
 *     asctime-date = wkday SP date3 SP time SP 4DIGIT
115
 *
116
 *     date1        = 2DIGIT SP month SP 4DIGIT
117
 *                    ; day month year (e.g., 02 Jun 1982)
118
 *     date2        = 2DIGIT "-" month "-" 2DIGIT
119
 *                    ; day-month-year (e.g., 02-Jun-82)
120
 *     date3        = month SP ( 2DIGIT | ( SP 1DIGIT ))
121
 *                    ; month day (e.g., Jun  2)
122
 *
123
 *     time         = 2DIGIT ":" 2DIGIT ":" 2DIGIT
124
 *                    ; 00:00:00 - 23:59:59
125
 *
126
 *     wkday        = "Mon" | "Tue" | "Wed"
127
 *                  | "Thu" | "Fri" | "Sat" | "Sun"
128
 *
129
 *     weekday      = "Monday" | "Tuesday" | "Wednesday"
130
 *                  | "Thursday" | "Friday" | "Saturday" | "Sunday"
131
 *
132
 *     month        = "Jan" | "Feb" | "Mar" | "Apr"
133
 *                  | "May" | "Jun" | "Jul" | "Aug"
134
 *                  | "Sep" | "Oct" | "Nov" | "Dec"
135
 *
136
 * However, for the sake of robustness (and Netscapeness), we ignore the
137
 * weekday and anything after the time field (including the timezone).
138
 *
139
 * This routine is intended to be very fast; 10x faster than using sscanf.
140
 *
141
 * Originally from Andrew Daviel <andrew@vancouver-webpages.com>, 29 Jul 96
142
 * but many changes since then.
143
 *
144
 */
145
APR_DECLARE(apr_time_t) apr_date_parse_http(const char *date)
146
0
{
147
0
    apr_time_exp_t ds;
148
0
    apr_time_t result;
149
0
    int mint, mon;
150
0
    const char *monstr, *timstr;
151
0
    static const int months[12] =
152
0
    {
153
0
    ('J' << 16) | ('a' << 8) | 'n', ('F' << 16) | ('e' << 8) | 'b',
154
0
    ('M' << 16) | ('a' << 8) | 'r', ('A' << 16) | ('p' << 8) | 'r',
155
0
    ('M' << 16) | ('a' << 8) | 'y', ('J' << 16) | ('u' << 8) | 'n',
156
0
    ('J' << 16) | ('u' << 8) | 'l', ('A' << 16) | ('u' << 8) | 'g',
157
0
    ('S' << 16) | ('e' << 8) | 'p', ('O' << 16) | ('c' << 8) | 't',
158
0
    ('N' << 16) | ('o' << 8) | 'v', ('D' << 16) | ('e' << 8) | 'c'};
159
160
0
    if (!date)
161
0
        return APR_DATE_BAD;
162
163
0
    while (*date && apr_isspace(*date))    /* Find first non-whitespace char */
164
0
        ++date;
165
166
0
    if (*date == '\0')
167
0
        return APR_DATE_BAD;
168
169
0
    if ((date = strchr(date, ' ')) == NULL)       /* Find space after weekday */
170
0
        return APR_DATE_BAD;
171
172
0
    ++date;        /* Now pointing to first char after space, which should be */
173
174
    /* start of the actual date information for all 4 formats. */
175
176
0
    if (apr_date_checkmask(date, "## @$$ #### ##:##:## *")) {
177
        /* RFC 1123 format with two days */
178
0
        ds.tm_year = ((date[7] - '0') * 10 + (date[8] - '0') - 19) * 100;
179
0
        if (ds.tm_year < 0)
180
0
            return APR_DATE_BAD;
181
182
0
        ds.tm_year += ((date[9] - '0') * 10) + (date[10] - '0');
183
184
0
        ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
185
186
0
        monstr = date + 3;
187
0
        timstr = date + 12;
188
0
    }
189
0
    else if (apr_date_checkmask(date, "##-@$$-## ##:##:## *")) {
190
        /* RFC 850 format */
191
0
        ds.tm_year = ((date[7] - '0') * 10) + (date[8] - '0');
192
0
        if (ds.tm_year < 70)
193
0
            ds.tm_year += 100;
194
195
0
        ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
196
197
0
        monstr = date + 3;
198
0
        timstr = date + 10;
199
0
    }
200
0
    else if (apr_date_checkmask(date, "@$$ ~# ##:##:## ####*")) {
201
        /* asctime format */
202
0
        ds.tm_year = ((date[16] - '0') * 10 + (date[17] - '0') - 19) * 100;
203
0
        if (ds.tm_year < 0)
204
0
            return APR_DATE_BAD;
205
206
0
        ds.tm_year += ((date[18] - '0') * 10) + (date[19] - '0');
207
208
0
        if (date[4] == ' ')
209
0
            ds.tm_mday = 0;
210
0
        else
211
0
            ds.tm_mday = (date[4] - '0') * 10;
212
213
0
        ds.tm_mday += (date[5] - '0');
214
215
0
        monstr = date;
216
0
        timstr = date + 7;
217
0
    }
218
0
    else if (apr_date_checkmask(date, "# @$$ #### ##:##:## *")) {
219
        /* RFC 1123 format with one day */
220
0
        ds.tm_year = ((date[6] - '0') * 10 + (date[7] - '0') - 19) * 100;
221
0
        if (ds.tm_year < 0)
222
0
            return APR_DATE_BAD;
223
224
0
        ds.tm_year += ((date[8] - '0') * 10) + (date[9] - '0');
225
226
0
        ds.tm_mday = (date[0] - '0');
227
228
0
        monstr = date + 2;
229
0
        timstr = date + 11;
230
0
    }
231
0
    else
232
0
        return APR_DATE_BAD;
233
234
0
    if (ds.tm_mday <= 0 || ds.tm_mday > 31)
235
0
        return APR_DATE_BAD;
236
237
0
    ds.tm_hour = ((timstr[0] - '0') * 10) + (timstr[1] - '0');
238
0
    ds.tm_min = ((timstr[3] - '0') * 10) + (timstr[4] - '0');
239
0
    ds.tm_sec = ((timstr[6] - '0') * 10) + (timstr[7] - '0');
240
241
0
    if ((ds.tm_hour > 23) || (ds.tm_min > 59) || (ds.tm_sec > 61))
242
0
        return APR_DATE_BAD;
243
244
0
    mint = (monstr[0] << 16) | (monstr[1] << 8) | monstr[2];
245
0
    for (mon = 0; mon < 12; mon++)
246
0
        if (mint == months[mon])
247
0
            break;
248
249
0
    if (mon == 12)
250
0
        return APR_DATE_BAD;
251
252
0
    if ((ds.tm_mday == 31) && (mon == 3 || mon == 5 || mon == 8 || mon == 10))
253
0
        return APR_DATE_BAD;
254
255
    /* February gets special check for leapyear */
256
0
    if ((mon == 1) &&
257
0
        ((ds.tm_mday > 29) ||
258
0
        ((ds.tm_mday == 29)
259
0
        && ((ds.tm_year & 3)
260
0
        || (((ds.tm_year % 100) == 0)
261
0
        && (((ds.tm_year % 400) != 100)))))))
262
0
        return APR_DATE_BAD;
263
264
0
    ds.tm_mon = mon;
265
266
    /* ap_mplode_time uses tm_usec and tm_gmtoff fields, but they haven't
267
     * been set yet.
268
     * It should be safe to just zero out these values.
269
     * tm_usec is the number of microseconds into the second.  HTTP only
270
     * cares about second granularity.
271
     * tm_gmtoff is the number of seconds off of GMT the time is.  By
272
     * definition all times going through this function are in GMT, so this
273
     * is zero.
274
     */
275
0
    ds.tm_usec = 0;
276
0
    ds.tm_gmtoff = 0;
277
0
    if (apr_time_exp_get(&result, &ds) != APR_SUCCESS)
278
0
        return APR_DATE_BAD;
279
280
0
    return result;
281
0
}
282
283
/*
284
 * Parses a string resembling an RFC 822 date.  This is meant to be
285
 * leinent in its parsing of dates.  Hence, this will parse a wider
286
 * range of dates than apr_date_parse_http.
287
 *
288
 * The prominent mailer (or poster, if mailer is unknown) that has
289
 * been seen in the wild is included for the unknown formats.
290
 *
291
 *     Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
292
 *     Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
293
 *     Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format
294
 *     Sun, 6 Nov 1994 08:49:37 GMT   ; RFC 822, updated by RFC 1123
295
 *     Sun, 06 Nov 94 08:49:37 GMT    ; RFC 822
296
 *     Sun, 6 Nov 94 08:49:37 GMT     ; RFC 822
297
 *     Sun, 06 Nov 94 08:49 GMT       ; Unknown [drtr@ast.cam.ac.uk]
298
 *     Sun, 6 Nov 94 08:49 GMT        ; Unknown [drtr@ast.cam.ac.uk]
299
 *     Sun, 06 Nov 94 8:49:37 GMT     ; Unknown [Elm 70.85]
300
 *     Sun, 6 Nov 94 8:49:37 GMT      ; Unknown [Elm 70.85]
301
 *     Mon,  7 Jan 2002 07:21:22 GMT  ; Unknown [Postfix]
302
 *     Sun, 06-Nov-1994 08:49:37 GMT  ; RFC 850 with four digit years
303
 *
304
 */
305
306
#define TIMEPARSE(ds,hr10,hr1,min10,min1,sec10,sec1)        \
307
0
    {                                                       \
308
0
        ds.tm_hour = ((hr10 - '0') * 10) + (hr1 - '0');     \
309
0
        ds.tm_min = ((min10 - '0') * 10) + (min1 - '0');    \
310
0
        ds.tm_sec = ((sec10 - '0') * 10) + (sec1 - '0');    \
311
0
    }
312
#define TIMEPARSE_STD(ds,timstr)                            \
313
0
    {                                                       \
314
0
        TIMEPARSE(ds, timstr[0],timstr[1],                  \
315
0
                      timstr[3],timstr[4],                  \
316
0
                      timstr[6],timstr[7]);                 \
317
0
    }
318
319
APR_DECLARE(apr_time_t) apr_date_parse_rfc(const char *date)
320
0
{
321
0
    apr_time_exp_t ds;
322
0
    apr_time_t result;
323
0
    int mint, mon;
324
0
    const char *monstr, *timstr, *gmtstr;
325
0
    static const int months[12] =
326
0
    {
327
0
    ('J' << 16) | ('a' << 8) | 'n', ('F' << 16) | ('e' << 8) | 'b',
328
0
    ('M' << 16) | ('a' << 8) | 'r', ('A' << 16) | ('p' << 8) | 'r',
329
0
    ('M' << 16) | ('a' << 8) | 'y', ('J' << 16) | ('u' << 8) | 'n',
330
0
    ('J' << 16) | ('u' << 8) | 'l', ('A' << 16) | ('u' << 8) | 'g',
331
0
    ('S' << 16) | ('e' << 8) | 'p', ('O' << 16) | ('c' << 8) | 't',
332
0
    ('N' << 16) | ('o' << 8) | 'v', ('D' << 16) | ('e' << 8) | 'c' };
333
334
0
    if (!date)
335
0
        return APR_DATE_BAD;
336
337
    /* Not all dates have text days at the beginning. */
338
0
    if (!apr_isdigit(date[0]))
339
0
    {
340
0
        while (*date && apr_isspace(*date)) /* Find first non-whitespace char */
341
0
            ++date;
342
343
0
        if (*date == '\0')
344
0
            return APR_DATE_BAD;
345
346
0
        if ((date = strchr(date, ' ')) == NULL)   /* Find space after weekday */
347
0
            return APR_DATE_BAD;
348
349
0
        ++date;    /* Now pointing to first char after space, which should be */    }
350
351
    /* start of the actual date information for all 11 formats. */
352
0
    if (apr_date_checkmask(date, "## @$$ #### ##:##:## *")) {   /* RFC 1123 format */
353
0
        ds.tm_year = ((date[7] - '0') * 10 + (date[8] - '0') - 19) * 100;
354
355
0
        if (ds.tm_year < 0)
356
0
            return APR_DATE_BAD;
357
358
0
        ds.tm_year += ((date[9] - '0') * 10) + (date[10] - '0');
359
360
0
        ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
361
362
0
        monstr = date + 3;
363
0
        timstr = date + 12;
364
0
        gmtstr = date + 21;
365
366
0
        TIMEPARSE_STD(ds, timstr);
367
0
    }
368
0
    else if (apr_date_checkmask(date, "##-@$$-## ##:##:## *")) {/* RFC 850 format  */
369
0
        ds.tm_year = ((date[7] - '0') * 10) + (date[8] - '0');
370
371
0
        if (ds.tm_year < 70)
372
0
            ds.tm_year += 100;
373
374
0
        ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
375
376
0
        monstr = date + 3;
377
0
        timstr = date + 10;
378
0
        gmtstr = date + 19;
379
380
0
        TIMEPARSE_STD(ds, timstr);
381
0
    }
382
0
    else if (apr_date_checkmask(date, "@$$ ~# ##:##:## ####*")) {
383
        /* asctime format */
384
0
        ds.tm_year = ((date[16] - '0') * 10 + (date[17] - '0') - 19) * 100;
385
0
        if (ds.tm_year < 0)
386
0
            return APR_DATE_BAD;
387
388
0
        ds.tm_year += ((date[18] - '0') * 10) + (date[19] - '0');
389
390
0
        if (date[4] == ' ')
391
0
            ds.tm_mday = 0;
392
0
        else
393
0
            ds.tm_mday = (date[4] - '0') * 10;
394
395
0
        ds.tm_mday += (date[5] - '0');
396
397
0
        monstr = date;
398
0
        timstr = date + 7;
399
0
        gmtstr = NULL;
400
401
0
        TIMEPARSE_STD(ds, timstr);
402
0
    }
403
0
    else if (apr_date_checkmask(date, "# @$$ #### ##:##:## *")) {
404
        /* RFC 1123 format*/
405
0
        ds.tm_year = ((date[6] - '0') * 10 + (date[7] - '0') - 19) * 100;
406
407
0
        if (ds.tm_year < 0)
408
0
            return APR_DATE_BAD;
409
410
0
        ds.tm_year += ((date[8] - '0') * 10) + (date[9] - '0');
411
0
        ds.tm_mday = (date[0] - '0');
412
413
0
        monstr = date + 2;
414
0
        timstr = date + 11;
415
0
        gmtstr = date + 20;
416
417
0
        TIMEPARSE_STD(ds, timstr);
418
0
    }
419
0
    else if (apr_date_checkmask(date, "## @$$ ## ##:##:## *")) {
420
        /* This is the old RFC 1123 date format - many many years ago, people
421
         * used two-digit years.  Oh, how foolish.
422
         *
423
         * Two-digit day, two-digit year version. */
424
0
        ds.tm_year = ((date[7] - '0') * 10) + (date[8] - '0');
425
426
0
        if (ds.tm_year < 70)
427
0
            ds.tm_year += 100;
428
429
0
        ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
430
431
0
        monstr = date + 3;
432
0
        timstr = date + 10;
433
0
        gmtstr = date + 19;
434
435
0
        TIMEPARSE_STD(ds, timstr);
436
0
    }
437
0
    else if (apr_date_checkmask(date, " # @$$ ## ##:##:## *")) {
438
        /* This is the old RFC 1123 date format - many many years ago, people
439
         * used two-digit years.  Oh, how foolish.
440
         *
441
         * Space + one-digit day, two-digit year version.*/
442
0
        ds.tm_year = ((date[7] - '0') * 10) + (date[8] - '0');
443
444
0
        if (ds.tm_year < 70)
445
0
            ds.tm_year += 100;
446
447
0
        ds.tm_mday = (date[1] - '0');
448
449
0
        monstr = date + 3;
450
0
        timstr = date + 10;
451
0
        gmtstr = date + 19;
452
453
0
        TIMEPARSE_STD(ds, timstr);
454
0
    }
455
0
    else if (apr_date_checkmask(date, "# @$$ ## ##:##:## *")) {
456
        /* This is the old RFC 1123 date format - many many years ago, people
457
         * used two-digit years.  Oh, how foolish.
458
         *
459
         * One-digit day, two-digit year version. */
460
0
        ds.tm_year = ((date[6] - '0') * 10) + (date[7] - '0');
461
462
0
        if (ds.tm_year < 70)
463
0
            ds.tm_year += 100;
464
465
0
        ds.tm_mday = (date[0] - '0');
466
467
0
        monstr = date + 2;
468
0
        timstr = date + 9;
469
0
        gmtstr = date + 18;
470
471
0
        TIMEPARSE_STD(ds, timstr);
472
0
    }
473
0
    else if (apr_date_checkmask(date, "## @$$ ## ##:## *")) {
474
        /* Loser format.  This is quite bogus.  */
475
0
        ds.tm_year = ((date[7] - '0') * 10) + (date[8] - '0');
476
477
0
        if (ds.tm_year < 70)
478
0
            ds.tm_year += 100;
479
480
0
        ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
481
482
0
        monstr = date + 3;
483
0
        timstr = date + 10;
484
0
        gmtstr = NULL;
485
486
0
        TIMEPARSE(ds, timstr[0],timstr[1], timstr[3],timstr[4], '0','0');
487
0
    }
488
0
    else if (apr_date_checkmask(date, "# @$$ ## ##:## *")) {
489
        /* Loser format.  This is quite bogus.  */
490
0
        ds.tm_year = ((date[6] - '0') * 10) + (date[7] - '0');
491
492
0
        if (ds.tm_year < 70)
493
0
            ds.tm_year += 100;
494
495
0
        ds.tm_mday = (date[0] - '0');
496
497
0
        monstr = date + 2;
498
0
        timstr = date + 9;
499
0
        gmtstr = NULL;
500
501
0
        TIMEPARSE(ds, timstr[0],timstr[1], timstr[3],timstr[4], '0','0');
502
0
    }
503
0
    else if (apr_date_checkmask(date, "## @$$ ## #:##:## *")) {
504
        /* Loser format.  This is quite bogus.  */
505
0
        ds.tm_year = ((date[7] - '0') * 10) + (date[8] - '0');
506
507
0
        if (ds.tm_year < 70)
508
0
            ds.tm_year += 100;
509
510
0
        ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
511
512
0
        monstr = date + 3;
513
0
        timstr = date + 9;
514
0
        gmtstr = date + 18;
515
516
0
        TIMEPARSE(ds, '0',timstr[1], timstr[3],timstr[4], timstr[6],timstr[7]);
517
0
    }
518
0
    else if (apr_date_checkmask(date, "# @$$ ## #:##:## *")) {
519
         /* Loser format.  This is quite bogus.  */
520
0
        ds.tm_year = ((date[6] - '0') * 10) + (date[7] - '0');
521
522
0
        if (ds.tm_year < 70)
523
0
            ds.tm_year += 100;
524
525
0
        ds.tm_mday = (date[0] - '0');
526
527
0
        monstr = date + 2;
528
0
        timstr = date + 8;
529
0
        gmtstr = date + 17;
530
531
0
        TIMEPARSE(ds, '0',timstr[1], timstr[3],timstr[4], timstr[6],timstr[7]);
532
0
    }
533
0
    else if (apr_date_checkmask(date, " # @$$ #### ##:##:## *")) {
534
        /* RFC 1123 format with a space instead of a leading zero. */
535
0
        ds.tm_year = ((date[7] - '0') * 10 + (date[8] - '0') - 19) * 100;
536
537
0
        if (ds.tm_year < 0)
538
0
            return APR_DATE_BAD;
539
540
0
        ds.tm_year += ((date[9] - '0') * 10) + (date[10] - '0');
541
542
0
        ds.tm_mday = (date[1] - '0');
543
544
0
        monstr = date + 3;
545
0
        timstr = date + 12;
546
0
        gmtstr = date + 21;
547
548
0
        TIMEPARSE_STD(ds, timstr);
549
0
    }
550
0
    else if (apr_date_checkmask(date, "##-@$$-#### ##:##:## *")) {
551
       /* RFC 1123 with dashes instead of spaces between date/month/year
552
        * This also looks like RFC 850 with four digit years.
553
        */
554
0
        ds.tm_year = ((date[7] - '0') * 10 + (date[8] - '0') - 19) * 100;
555
0
        if (ds.tm_year < 0)
556
0
            return APR_DATE_BAD;
557
558
0
        ds.tm_year += ((date[9] - '0') * 10) + (date[10] - '0');
559
560
0
        ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
561
562
0
        monstr = date + 3;
563
0
        timstr = date + 12;
564
0
        gmtstr = date + 21;
565
566
0
        TIMEPARSE_STD(ds, timstr);
567
0
    }
568
0
    else
569
0
        return APR_DATE_BAD;
570
571
0
    if (ds.tm_mday <= 0 || ds.tm_mday > 31)
572
0
        return APR_DATE_BAD;
573
574
0
    if ((ds.tm_hour > 23) || (ds.tm_min > 59) || (ds.tm_sec > 61))
575
0
        return APR_DATE_BAD;
576
577
0
    mint = (monstr[0] << 16) | (monstr[1] << 8) | monstr[2];
578
0
    for (mon = 0; mon < 12; mon++)
579
0
        if (mint == months[mon])
580
0
            break;
581
582
0
    if (mon == 12)
583
0
        return APR_DATE_BAD;
584
585
0
    if ((ds.tm_mday == 31) && (mon == 3 || mon == 5 || mon == 8 || mon == 10))
586
0
        return APR_DATE_BAD;
587
588
    /* February gets special check for leapyear */
589
590
0
    if ((mon == 1) &&
591
0
        ((ds.tm_mday > 29)
592
0
        || ((ds.tm_mday == 29)
593
0
        && ((ds.tm_year & 3)
594
0
        || (((ds.tm_year % 100) == 0)
595
0
        && (((ds.tm_year % 400) != 100)))))))
596
0
        return APR_DATE_BAD;
597
598
0
    ds.tm_mon = mon;
599
600
    /* tm_gmtoff is the number of seconds off of GMT the time is.
601
     *
602
     * We only currently support: [+-]ZZZZ where Z is the offset in
603
     * hours from GMT.
604
     *
605
     * If there is any confusion, tm_gmtoff will remain 0.
606
     */
607
0
    ds.tm_gmtoff = 0;
608
609
    /* Do we have a timezone ? */
610
0
    if (gmtstr) {
611
0
        int offset;
612
0
        switch (*gmtstr) {
613
0
        case '-':
614
0
            offset = atoi(gmtstr+1);
615
0
            ds.tm_gmtoff -= (offset / 100) * 60 * 60;
616
0
            ds.tm_gmtoff -= (offset % 100) * 60;
617
0
            break;
618
0
        case '+':
619
0
            offset = atoi(gmtstr+1);
620
0
            ds.tm_gmtoff += (offset / 100) * 60 * 60;
621
0
            ds.tm_gmtoff += (offset % 100) * 60;
622
0
            break;
623
0
        }
624
0
    }
625
626
    /* apr_time_exp_get uses tm_usec field, but it hasn't been set yet.
627
     * It should be safe to just zero out this value.
628
     * tm_usec is the number of microseconds into the second.  HTTP only
629
     * cares about second granularity.
630
     */
631
0
    ds.tm_usec = 0;
632
633
0
    if (apr_time_exp_gmt_get(&result, &ds) != APR_SUCCESS)
634
0
        return APR_DATE_BAD;
635
636
0
    return result;
637
0
}