Mercurial > hg > nginx-quic
annotate src/core/ngx_parse.c @ 6682:db422604ceb0
Stream: allow using the session context inside handlers.
Previously, it was not possible to use the stream context
inside ngx_stream_init_connection() handlers. Now, limit_conn,
access handlers, as well as those added later, can create
their own contexts.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Tue, 06 Sep 2016 21:28:17 +0300 |
parents | 4ccb37b04454 |
children | 87cf6ddb41c2 |
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; |
1971 | 20 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
|
21 |
1971 | 22 switch (unit) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 case 'K': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 case 'k': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 len--; |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
26 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
|
27 scale = 1024; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 case 'M': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 case 'm': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 len--; |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
33 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
|
34 scale = 1024 * 1024; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 default: |
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; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 scale = 1; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 |
563 | 42 size = ngx_atosz(line->data, len); |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
43 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
|
44 return NGX_ERROR; |
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 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 size *= scale; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 return size; |
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 |
663 | 53 off_t |
54 ngx_parse_offset(ngx_str_t *line) | |
55 { | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
56 u_char unit; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
57 off_t offset, scale, max; |
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
58 size_t len; |
663 | 59 |
60 len = line->len; | |
1971 | 61 unit = line->data[len - 1]; |
663 | 62 |
1971 | 63 switch (unit) { |
663 | 64 case 'K': |
65 case 'k': | |
66 len--; | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
67 max = NGX_MAX_OFF_T_VALUE / 1024; |
663 | 68 scale = 1024; |
69 break; | |
70 | |
71 case 'M': | |
72 case 'm': | |
73 len--; | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
74 max = NGX_MAX_OFF_T_VALUE / (1024 * 1024); |
663 | 75 scale = 1024 * 1024; |
76 break; | |
77 | |
78 case 'G': | |
79 case 'g': | |
80 len--; | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
81 max = NGX_MAX_OFF_T_VALUE / (1024 * 1024 * 1024); |
663 | 82 scale = 1024 * 1024 * 1024; |
83 break; | |
84 | |
85 default: | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
86 max = NGX_MAX_OFF_T_VALUE; |
663 | 87 scale = 1; |
88 } | |
89 | |
90 offset = ngx_atoof(line->data, len); | |
6009
15a15f6ae3a2
Core: overflow detection in number parsing functions.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
91 if (offset == NGX_ERROR || offset > max) { |
663 | 92 return NGX_ERROR; |
93 } | |
94 | |
95 offset *= scale; | |
96 | |
97 return offset; | |
98 } | |
99 | |
100 | |
563 | 101 ngx_int_t |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
102 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
|
103 { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
104 u_char *p, *last; |
651 | 105 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
|
106 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
|
107 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
|
108 enum { |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 st_start = 0, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 st_year, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 st_month, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 st_week, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 st_day, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 st_hour, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 st_min, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 st_sec, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 st_msec, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 st_last |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 } step; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
121 valid = 0; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
122 value = 0; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 total = 0; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
124 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
|
125 cutlim = NGX_MAX_INT_T_VALUE % 10; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
126 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
|
127 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
128 p = line->data; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
129 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
|
130 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
131 while (p < last) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
133 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
|
134 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
|
135 return NGX_ERROR; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
136 } |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
137 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
138 value = value * 10 + (*p++ - '0'); |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
139 valid = 1; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
140 continue; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 } |
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 switch (*p++) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 case 'y': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 if (step > st_start) { |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 step = st_year; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
150 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
|
151 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
|
152 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 case 'M': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
155 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
|
156 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 step = st_month; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
159 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
|
160 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
|
161 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 case 'w': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
164 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
|
165 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 step = st_week; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
168 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
|
169 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
|
170 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 case 'd': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
173 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
|
174 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 step = st_day; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
177 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
|
178 scale = 60 * 60 * 24; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 case 'h': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
182 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
|
183 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 step = st_hour; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
186 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
|
187 scale = 60 * 60; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 case 'm': |
6287
4ccb37b04454
Fixed ngx_parse_time() out of bounds access (ticket #821).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6011
diff
changeset
|
191 if (p < last && *p == 's') { |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
192 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
|
193 return NGX_ERROR; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
194 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
195 p++; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
196 step = st_msec; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
197 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
|
198 scale = 1; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
199 break; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
200 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
201 |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
202 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
|
203 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
204 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
205 step = st_min; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
206 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
|
207 scale = 60; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
209 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
210 case 's': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
211 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
|
212 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
213 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
214 step = st_sec; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
215 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
|
216 scale = 1; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
217 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
218 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
219 case ' ': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
220 if (step >= st_sec) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
221 return NGX_ERROR; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
222 } |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 step = st_last; |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
224 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
|
225 scale = 1; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
226 break; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
227 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
228 default: |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
229 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
232 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
|
233 scale *= 1000; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
234 max /= 1000; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
235 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
236 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
237 if (value > max) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
238 return NGX_ERROR; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
239 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
240 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
241 value *= scale; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
243 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
|
244 return NGX_ERROR; |
157
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 total += value; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
248 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
249 value = 0; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
250 |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
251 while (p < last && *p == ' ') { |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
252 p++; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
253 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
254 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
256 if (!valid) { |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
257 return NGX_ERROR; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
258 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
259 |
6011
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
260 if (!is_sec) { |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
261 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
|
262 return NGX_ERROR; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
263 } |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
264 |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
265 value *= 1000; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
266 } |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
267 |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
268 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
|
269 return NGX_ERROR; |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
270 } |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
271 |
429a8c65f0a7
Core: overflow detection in ngx_parse_time() (ticket #732).
Ruslan Ermilov <ru@nginx.com>
parents:
6010
diff
changeset
|
272 return total + value; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
273 } |