Mercurial > hg > nginx-quic
annotate src/core/ngx_parse.c @ 7870:e169cce912c7 quic
Avoid retransmitting of packets with discarded keys.
Sections 4.10.1 and 4.10.2 of quic transport describe discarding of initial
and handshake keys. Since the keys are discarded, we no longer need
to retransmit packets and corresponding queues should be emptied.
This patch removes previously added workaround that did not require
acknowledgement for initial packets, resulting in avoiding retransmission,
which is wrong because a packet could be lost and we have to retransmit it.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 18 May 2020 13:54:53 +0300 |
parents | 87cf6ddb41c2 |
children |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
6 |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
563 | 12 ssize_t |
13 ngx_parse_size(ngx_str_t *line) | |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 { |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
15 u_char unit; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
16 size_t len; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
17 ssize_t size, scale, max; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
18 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 len = line->len; |
6917
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
20 |
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
21 if (len == 0) { |
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
22 return NGX_ERROR; |
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
23 } |
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
24 |
1971 | 25 unit = line->data[len - 1]; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 |
1971 | 27 switch (unit) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 case 'K': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 case 'k': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 len--; |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
31 max = NGX_MAX_SIZE_T_VALUE / 1024; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 scale = 1024; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 case 'M': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 case 'm': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 len--; |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
38 max = NGX_MAX_SIZE_T_VALUE / (1024 * 1024); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 scale = 1024 * 1024; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 default: |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
43 max = NGX_MAX_SIZE_T_VALUE; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 scale = 1; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
563 | 47 size = ngx_atosz(line->data, len); |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
48 if (size == NGX_ERROR || size > max) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 size *= scale; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 return size; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 |
663 | 58 off_t |
59 ngx_parse_offset(ngx_str_t *line) | |
60 { | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
61 u_char unit; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
62 off_t offset, scale, max; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
63 size_t len; |
663 | 64 |
65 len = line->len; | |
6917
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
66 |
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
67 if (len == 0) { |
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
68 return NGX_ERROR; |
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
69 } |
87cf6ddb41c2
Fixed ngx_parse_size() / ngx_parse_offset() with 0-length strings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6287
diff
changeset
|
70 |
1971 | 71 unit = line->data[len - 1]; |
663 | 72 |
1971 | 73 switch (unit) { |
663 | 74 case 'K': |
75 case 'k': | |
76 len--; | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
77 max = NGX_MAX_OFF_T_VALUE / 1024; |
663 | 78 scale = 1024; |
79 break; | |
80 | |
81 case 'M': | |
82 case 'm': | |
83 len--; | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
84 max = NGX_MAX_OFF_T_VALUE / (1024 * 1024); |
663 | 85 scale = 1024 * 1024; |
86 break; | |
87 | |
88 case 'G': | |
89 case 'g': | |
90 len--; | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
91 max = NGX_MAX_OFF_T_VALUE / (1024 * 1024 * 1024); |
663 | 92 scale = 1024 * 1024 * 1024; |
93 break; | |
94 | |
95 default: | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
96 max = NGX_MAX_OFF_T_VALUE; |
663 | 97 scale = 1; |
98 } | |
99 | |
100 offset = ngx_atoof(line->data, len); | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
101 if (offset == NGX_ERROR || offset > max) { |
663 | 102 return NGX_ERROR; |
103 } | |
104 | |
105 offset *= scale; | |
106 | |
107 return offset; | |
108 } | |
109 | |
110 | |
563 | 111 ngx_int_t |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
112 ngx_parse_time(ngx_str_t *line, ngx_uint_t is_sec) |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
114 u_char *p, *last; |
651 | 115 ngx_int_t value, total, scale; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
116 ngx_int_t max, cutoff, cutlim; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
117 ngx_uint_t valid; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 enum { |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 st_start = 0, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 st_year, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 st_month, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 st_week, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 st_day, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 st_hour, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 st_min, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 st_sec, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 st_msec, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 st_last |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 } step; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
131 valid = 0; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
132 value = 0; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 total = 0; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
134 cutoff = NGX_MAX_INT_T_VALUE / 10; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
135 cutlim = NGX_MAX_INT_T_VALUE % 10; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
136 step = is_sec ? st_start : st_month; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
138 p = line->data; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
139 last = p + line->len; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
141 while (p < last) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
143 if (*p >= '0' && *p <= '9') { |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
144 if (value >= cutoff && (value > cutoff || *p - '0' > cutlim)) { |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
145 return NGX_ERROR; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
146 } |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
147 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
148 value = value * 10 + (*p++ - '0'); |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
149 valid = 1; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
150 continue; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
153 switch (*p++) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 case 'y': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 if (step > st_start) { |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 step = st_year; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
160 max = NGX_MAX_INT_T_VALUE / (60 * 60 * 24 * 365); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 scale = 60 * 60 * 24 * 365; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 case 'M': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
165 if (step >= st_month) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 step = st_month; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
169 max = NGX_MAX_INT_T_VALUE / (60 * 60 * 24 * 30); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 scale = 60 * 60 * 24 * 30; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 case 'w': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
174 if (step >= st_week) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 step = st_week; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
178 max = NGX_MAX_INT_T_VALUE / (60 * 60 * 24 * 7); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 scale = 60 * 60 * 24 * 7; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 case 'd': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
183 if (step >= st_day) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 step = st_day; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
187 max = NGX_MAX_INT_T_VALUE / (60 * 60 * 24); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 scale = 60 * 60 * 24; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
191 case 'h': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
192 if (step >= st_hour) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 step = st_hour; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
196 max = NGX_MAX_INT_T_VALUE / (60 * 60); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 scale = 60 * 60; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
198 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 case 'm': |
6287
4ccb37b04454
Fixed ngx_parse_time() out of bounds access (ticket #821).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6011
diff
changeset
|
201 if (p < last && *p == 's') { |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
202 if (is_sec || step >= st_msec) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
203 return NGX_ERROR; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
204 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
205 p++; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
206 step = st_msec; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
207 max = NGX_MAX_INT_T_VALUE; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
208 scale = 1; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
209 break; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
210 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
211 |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
212 if (step >= st_min) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
213 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
214 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
215 step = st_min; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
216 max = NGX_MAX_INT_T_VALUE / 60; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
217 scale = 60; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
218 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
219 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 case 's': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
221 if (step >= st_sec) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
222 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
224 step = st_sec; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
225 max = NGX_MAX_INT_T_VALUE; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
226 scale = 1; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
227 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
229 case ' ': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
230 if (step >= st_sec) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
231 return NGX_ERROR; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
232 } |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
233 step = st_last; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
234 max = NGX_MAX_INT_T_VALUE; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
235 scale = 1; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
236 break; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
237 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
238 default: |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
239 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
240 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
241 |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
242 if (step != st_msec && !is_sec) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
243 scale *= 1000; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
244 max /= 1000; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
247 if (value > max) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
248 return NGX_ERROR; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
249 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
250 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
251 value *= scale; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
252 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
253 if (total > NGX_MAX_INT_T_VALUE - value) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
254 return NGX_ERROR; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
256 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
257 total += value; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
258 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
259 value = 0; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
260 |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
261 while (p < last && *p == ' ') { |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
262 p++; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
263 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
264 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
265 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
266 if (!valid) { |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
267 return NGX_ERROR; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
268 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
269 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
270 if (!is_sec) { |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
271 if (value > NGX_MAX_INT_T_VALUE / 1000) { |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
272 return NGX_ERROR; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
273 } |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
274 |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
275 value *= 1000; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
276 } |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
277 |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
278 if (total > NGX_MAX_INT_T_VALUE - value) { |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
279 return NGX_ERROR; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
280 } |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
281 |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
282 return total + value; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
283 } |