Time parsing cleanup.
Nuke NGX_PARSE_LARGE_TIME, it's not used since 0.6.30. The only error
ngx_parse_time() can currently return is NGX_ERROR, check it explicitly
and make sure to cast it to appropriate type (either time_t or ngx_msec_t)
to avoid signedness warnings on platforms with unsigned time_t (notably QNX).
Maxim Dounin
10 years ago
1294 | 1294 | return "invalid value"; |
1295 | 1295 | } |
1296 | 1296 | |
1297 | if (*msp == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { | |
1298 | return "value must be less than 597 hours"; | |
1299 | } | |
1300 | ||
1301 | 1297 | if (cmd->post) { |
1302 | 1298 | post = cmd->post; |
1303 | 1299 | return post->post_handler(cf, post, msp); |
1325 | 1321 | value = cf->args->elts; |
1326 | 1322 | |
1327 | 1323 | *sp = ngx_parse_time(&value[1], 1); |
1328 | if (*sp == NGX_ERROR) { | |
1324 | if (*sp == (time_t) NGX_ERROR) { | |
1329 | 1325 | return "invalid value"; |
1330 | } | |
1331 | ||
1332 | if (*sp == NGX_PARSE_LARGE_TIME) { | |
1333 | return "value must be less than 68 years"; | |
1334 | 1326 | } |
1335 | 1327 | |
1336 | 1328 | if (cmd->post) { |
12 | 12 | #include <ngx_core.h> |
13 | 13 | |
14 | 14 | |
15 | #define NGX_PARSE_LARGE_TIME -2 | |
16 | ||
17 | ||
18 | 15 | ssize_t ngx_parse_size(ngx_str_t *line); |
19 | 16 | off_t ngx_parse_offset(ngx_str_t *line); |
20 | 17 | ngx_int_t ngx_parse_time(ngx_str_t *line, ngx_uint_t is_sec); |
159 | 159 | |
160 | 160 | r->valid = ngx_parse_time(&s, 1); |
161 | 161 | |
162 | if (r->valid == NGX_ERROR) { | |
162 | if (r->valid == (time_t) NGX_ERROR) { | |
163 | 163 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
164 | 164 | "invalid parameter: %V", &names[i]); |
165 | 165 | return NULL; |
529 | 529 | |
530 | 530 | hcf->expires_time = ngx_parse_time(&value[n], 1); |
531 | 531 | |
532 | if (hcf->expires_time == NGX_ERROR) { | |
532 | if (hcf->expires_time == (time_t) NGX_ERROR) { | |
533 | 533 | return "invalid value"; |
534 | 534 | } |
535 | 535 | |
537 | 537 | && hcf->expires_time > 24 * 60 * 60) |
538 | 538 | { |
539 | 539 | return "daily time value must be less than 24 hours"; |
540 | } | |
541 | ||
542 | if (hcf->expires_time == NGX_PARSE_LARGE_TIME) { | |
543 | return "value must be less than 68 years"; | |
544 | 540 | } |
545 | 541 | |
546 | 542 | if (minus) { |
1248 | 1248 | s.data = value[i].data + 9; |
1249 | 1249 | |
1250 | 1250 | inactive = ngx_parse_time(&s, 1); |
1251 | if (inactive < 0) { | |
1251 | if (inactive == (time_t) NGX_ERROR) { | |
1252 | 1252 | goto failed; |
1253 | 1253 | } |
1254 | 1254 | |
1271 | 1271 | s.data = value[i].data + 6; |
1272 | 1272 | |
1273 | 1273 | valid = ngx_parse_time(&s, 1); |
1274 | if (valid < 0) { | |
1274 | if (valid == (time_t) NGX_ERROR) { | |
1275 | 1275 | goto failed; |
1276 | 1276 | } |
1277 | 1277 |
773 | 773 | } |
774 | 774 | |
775 | 775 | ucf->expires = ngx_parse_time(&value[1], 1); |
776 | if (ucf->expires == NGX_ERROR) { | |
776 | if (ucf->expires == (time_t) NGX_ERROR) { | |
777 | 777 | return "invalid value"; |
778 | } | |
779 | ||
780 | if (ucf->expires == NGX_PARSE_LARGE_TIME) { | |
781 | return "value must be less than 68 years"; | |
782 | 778 | } |
783 | 779 | |
784 | 780 | return NGX_CONF_OK; |
273 | 273 | line.data = value[i].data + 2; |
274 | 274 | |
275 | 275 | bl->timeout = ngx_parse_time(&line, 1); |
276 | if (bl->timeout == NGX_ERROR) { | |
276 | if (bl->timeout == (time_t) NGX_ERROR) { | |
277 | 277 | invalid = 1; |
278 | 278 | break; |
279 | 279 | } |
3852 | 3852 | s.len = p - s.data; |
3853 | 3853 | |
3854 | 3854 | lsopt.tcp_keepidle = ngx_parse_time(&s, 1); |
3855 | if (lsopt.tcp_keepidle == NGX_ERROR) { | |
3855 | if (lsopt.tcp_keepidle == (time_t) NGX_ERROR) { | |
3856 | 3856 | goto invalid_so_keepalive; |
3857 | 3857 | } |
3858 | 3858 | } |
3868 | 3868 | s.len = p - s.data; |
3869 | 3869 | |
3870 | 3870 | lsopt.tcp_keepintvl = ngx_parse_time(&s, 1); |
3871 | if (lsopt.tcp_keepintvl == NGX_ERROR) { | |
3871 | if (lsopt.tcp_keepintvl == (time_t) NGX_ERROR) { | |
3872 | 3872 | goto invalid_so_keepalive; |
3873 | 3873 | } |
3874 | 3874 | } |
4515 | 4515 | s.data = value[i].data + 9; |
4516 | 4516 | |
4517 | 4517 | inactive = ngx_parse_time(&s, 1); |
4518 | if (inactive < 0) { | |
4518 | if (inactive == (time_t) NGX_ERROR) { | |
4519 | 4519 | goto failed; |
4520 | 4520 | } |
4521 | 4521 | |
4602 | 4602 | return "invalid value"; |
4603 | 4603 | } |
4604 | 4604 | |
4605 | if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { | |
4606 | return "value must be less than 597 hours"; | |
4607 | } | |
4608 | ||
4609 | 4605 | if (cf->args->nelts == 2) { |
4610 | 4606 | return NGX_CONF_OK; |
4611 | 4607 | } |
4612 | 4608 | |
4613 | 4609 | clcf->keepalive_header = ngx_parse_time(&value[2], 1); |
4614 | 4610 | |
4615 | if (clcf->keepalive_header == NGX_ERROR) { | |
4611 | if (clcf->keepalive_header == (time_t) NGX_ERROR) { | |
4616 | 4612 | return "invalid value"; |
4617 | } | |
4618 | ||
4619 | if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) { | |
4620 | return "value must be less than 68 years"; | |
4621 | 4613 | } |
4622 | 4614 | |
4623 | 4615 | return NGX_CONF_OK; |
1596 | 1596 | time_t inactive; |
1597 | 1597 | ssize_t size; |
1598 | 1598 | ngx_str_t s, name, *value; |
1599 | ngx_int_t loader_files, loader_sleep, loader_threshold; | |
1599 | ngx_int_t loader_files; | |
1600 | ngx_msec_t loader_sleep, loader_threshold; | |
1600 | 1601 | ngx_uint_t i, n; |
1601 | 1602 | ngx_http_file_cache_t *cache; |
1602 | 1603 | |
1703 | 1704 | s.data = value[i].data + 9; |
1704 | 1705 | |
1705 | 1706 | inactive = ngx_parse_time(&s, 1); |
1706 | if (inactive < 0) { | |
1707 | if (inactive == (time_t) NGX_ERROR) { | |
1707 | 1708 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1708 | 1709 | "invalid inactive value \"%V\"", &value[i]); |
1709 | 1710 | return NGX_CONF_ERROR; |
1745 | 1746 | s.data = value[i].data + 13; |
1746 | 1747 | |
1747 | 1748 | loader_sleep = ngx_parse_time(&s, 0); |
1748 | if (loader_sleep < 0) { | |
1749 | if (loader_sleep == (ngx_msec_t) NGX_ERROR) { | |
1749 | 1750 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1750 | 1751 | "invalid loader_sleep value \"%V\"", &value[i]); |
1751 | 1752 | return NGX_CONF_ERROR; |
1760 | 1761 | s.data = value[i].data + 17; |
1761 | 1762 | |
1762 | 1763 | loader_threshold = ngx_parse_time(&s, 0); |
1763 | if (loader_threshold < 0) { | |
1764 | if (loader_threshold == (ngx_msec_t) NGX_ERROR) { | |
1764 | 1765 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1765 | 1766 | "invalid loader_threshold value \"%V\"", &value[i]); |
1766 | 1767 | return NGX_CONF_ERROR; |
1787 | 1788 | cache->path->conf_file = cf->conf_file->file.name.data; |
1788 | 1789 | cache->path->line = cf->conf_file->line; |
1789 | 1790 | cache->loader_files = loader_files; |
1790 | cache->loader_sleep = (ngx_msec_t) loader_sleep; | |
1791 | cache->loader_threshold = (ngx_msec_t) loader_threshold; | |
1791 | cache->loader_sleep = loader_sleep; | |
1792 | cache->loader_threshold = loader_threshold; | |
1792 | 1793 | |
1793 | 1794 | if (ngx_add_path(cf, &cache->path) != NGX_OK) { |
1794 | 1795 | return NGX_CONF_ERROR; |
1842 | 1843 | n = cf->args->nelts - 1; |
1843 | 1844 | |
1844 | 1845 | valid = ngx_parse_time(&value[n], 1); |
1845 | if (valid < 0) { | |
1846 | if (valid == (time_t) NGX_ERROR) { | |
1846 | 1847 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1847 | 1848 | "invalid time value \"%V\"", &value[n]); |
1848 | 1849 | return NGX_CONF_ERROR; |
4267 | 4267 | |
4268 | 4268 | fail_timeout = ngx_parse_time(&s, 1); |
4269 | 4269 | |
4270 | if (fail_timeout == NGX_ERROR) { | |
4270 | if (fail_timeout == (time_t) NGX_ERROR) { | |
4271 | 4271 | goto invalid; |
4272 | 4272 | } |
4273 | 4273 |
478 | 478 | s.len = p - s.data; |
479 | 479 | |
480 | 480 | ls->tcp_keepidle = ngx_parse_time(&s, 1); |
481 | if (ls->tcp_keepidle == NGX_ERROR) { | |
481 | if (ls->tcp_keepidle == (time_t) NGX_ERROR) { | |
482 | 482 | goto invalid_so_keepalive; |
483 | 483 | } |
484 | 484 | } |
494 | 494 | s.len = p - s.data; |
495 | 495 | |
496 | 496 | ls->tcp_keepintvl = ngx_parse_time(&s, 1); |
497 | if (ls->tcp_keepintvl == NGX_ERROR) { | |
497 | if (ls->tcp_keepintvl == (time_t) NGX_ERROR) { | |
498 | 498 | goto invalid_so_keepalive; |
499 | 499 | } |
500 | 500 | } |