mirror of
https://github.com/nginx/nginx.git
synced 2025-06-09 19:12:47 +08:00
allow time without spaces in ngx_parse_time()
This commit is contained in:
parent
2e39e289e1
commit
f57b24e70f
@ -93,12 +93,11 @@ ngx_parse_offset(ngx_str_t *line)
|
|||||||
|
|
||||||
|
|
||||||
ngx_int_t
|
ngx_int_t
|
||||||
ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
|
ngx_parse_time(ngx_str_t *line, ngx_uint_t sec)
|
||||||
{
|
{
|
||||||
size_t len;
|
u_char *p, *last;
|
||||||
u_char *start, last;
|
|
||||||
ngx_int_t value, total, scale;
|
ngx_int_t value, total, scale;
|
||||||
ngx_uint_t max, i;
|
ngx_uint_t max, valid;
|
||||||
enum {
|
enum {
|
||||||
st_start = 0,
|
st_start = 0,
|
||||||
st_year,
|
st_year,
|
||||||
@ -112,39 +111,30 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
|
|||||||
st_last
|
st_last
|
||||||
} step;
|
} step;
|
||||||
|
|
||||||
|
valid = 0;
|
||||||
start = line->data;
|
value = 0;
|
||||||
len = 0;
|
|
||||||
total = 0;
|
total = 0;
|
||||||
step = sec ? st_start : st_month;
|
step = sec ? st_start : st_month;
|
||||||
|
scale = sec ? 1 : 1000;
|
||||||
|
|
||||||
for (i = 0; /* void */ ; i++) {
|
p = line->data;
|
||||||
|
last = p + line->len;
|
||||||
|
|
||||||
if (i < line->len) {
|
while (p < last) {
|
||||||
if (line->data[i] != ' ') {
|
|
||||||
len++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line->data[i] == ' ' && len == 0) {
|
if (*p >= '0' && *p <= '9') {
|
||||||
start = &line->data[i + 1];
|
value = value * 10 + (*p++ - '0');
|
||||||
continue;
|
valid = 1;
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 0) {
|
switch (*p++) {
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
last = line->data[i - 1];
|
|
||||||
|
|
||||||
switch (last) {
|
|
||||||
case 'y':
|
case 'y':
|
||||||
if (step > st_start) {
|
if (step > st_start) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
step = st_year;
|
step = st_year;
|
||||||
len--;
|
|
||||||
max = 68;
|
max = 68;
|
||||||
scale = 60 * 60 * 24 * 365;
|
scale = 60 * 60 * 24 * 365;
|
||||||
break;
|
break;
|
||||||
@ -154,7 +144,6 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
step = st_month;
|
step = st_month;
|
||||||
len--;
|
|
||||||
max = 828;
|
max = 828;
|
||||||
scale = 60 * 60 * 24 * 30;
|
scale = 60 * 60 * 24 * 30;
|
||||||
break;
|
break;
|
||||||
@ -164,7 +153,6 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
step = st_week;
|
step = st_week;
|
||||||
len--;
|
|
||||||
max = 3550;
|
max = 3550;
|
||||||
scale = 60 * 60 * 24 * 7;
|
scale = 60 * 60 * 24 * 7;
|
||||||
break;
|
break;
|
||||||
@ -174,7 +162,6 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
step = st_day;
|
step = st_day;
|
||||||
len--;
|
|
||||||
max = 24855;
|
max = 24855;
|
||||||
scale = 60 * 60 * 24;
|
scale = 60 * 60 * 24;
|
||||||
break;
|
break;
|
||||||
@ -184,52 +171,49 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
step = st_hour;
|
step = st_hour;
|
||||||
len--;
|
|
||||||
max = 596523;
|
max = 596523;
|
||||||
scale = 60 * 60;
|
scale = 60 * 60;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if (step > st_hour) {
|
if (*p == 's') {
|
||||||
return NGX_ERROR;
|
|
||||||
}
|
|
||||||
step = st_min;
|
|
||||||
len--;
|
|
||||||
max = 35791394;
|
|
||||||
scale = 60;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 's':
|
|
||||||
len--;
|
|
||||||
|
|
||||||
if (line->data[i - 2] == 'm') {
|
|
||||||
if (sec || step > st_sec) {
|
if (sec || step > st_sec) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
p++;
|
||||||
step = st_msec;
|
step = st_msec;
|
||||||
len--;
|
|
||||||
max = 2147483647;
|
max = 2147483647;
|
||||||
scale = 1;
|
scale = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (step > st_hour) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
step = st_min;
|
||||||
|
max = 35791394;
|
||||||
|
scale = 60;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
if (step > st_min) {
|
if (step > st_min) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
step = st_sec;
|
step = st_sec;
|
||||||
max = 2147483647;
|
max = 2147483647;
|
||||||
scale = 1;
|
scale = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case ' ':
|
||||||
|
if (step > st_min) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
step = st_last;
|
step = st_last;
|
||||||
max = 2147483647;
|
max = 2147483647;
|
||||||
scale = 1;
|
scale = 1;
|
||||||
}
|
break;
|
||||||
|
|
||||||
value = ngx_atoi(start, len);
|
default:
|
||||||
if (value == NGX_ERROR) {
|
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,23 +222,27 @@ ngx_parse_time(ngx_str_t *line, ngx_int_t sec)
|
|||||||
max /= 1000;
|
max /= 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((u_int) value > max) {
|
if ((ngx_uint_t) value > max) {
|
||||||
return NGX_PARSE_LARGE_TIME;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
total += value * scale;
|
total += value * scale;
|
||||||
|
|
||||||
if ((u_int) total > 2147483647) {
|
if ((ngx_uint_t) total > 2147483647) {
|
||||||
return NGX_PARSE_LARGE_TIME;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= line->len) {
|
value = 0;
|
||||||
break;
|
scale = sec ? 1 : 1000;
|
||||||
}
|
|
||||||
|
|
||||||
len = 0;
|
while (p < last && *p == ' ') {
|
||||||
start = &line->data[i + 1];
|
p++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return total;
|
if (valid) {
|
||||||
|
return total + value * scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
ssize_t ngx_parse_size(ngx_str_t *line);
|
ssize_t ngx_parse_size(ngx_str_t *line);
|
||||||
off_t ngx_parse_offset(ngx_str_t *line);
|
off_t ngx_parse_offset(ngx_str_t *line);
|
||||||
ngx_int_t ngx_parse_time(ngx_str_t *line, ngx_int_t sec);
|
ngx_int_t ngx_parse_time(ngx_str_t *line, ngx_uint_t sec);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NGX_PARSE_H_INCLUDED_ */
|
#endif /* _NGX_PARSE_H_INCLUDED_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user