Klaus Demo nginx / 9f38b20
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
11 changed file(s) with 22 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
12941294 return "invalid value";
12951295 }
12961296
1297 if (*msp == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
1298 return "value must be less than 597 hours";
1299 }
1300
13011297 if (cmd->post) {
13021298 post = cmd->post;
13031299 return post->post_handler(cf, post, msp);
13251321 value = cf->args->elts;
13261322
13271323 *sp = ngx_parse_time(&value[1], 1);
1328 if (*sp == NGX_ERROR) {
1324 if (*sp == (time_t) NGX_ERROR) {
13291325 return "invalid value";
1330 }
1331
1332 if (*sp == NGX_PARSE_LARGE_TIME) {
1333 return "value must be less than 68 years";
13341326 }
13351327
13361328 if (cmd->post) {
1212 #include <ngx_core.h>
1313
1414
15 #define NGX_PARSE_LARGE_TIME -2
16
17
1815 ssize_t ngx_parse_size(ngx_str_t *line);
1916 off_t ngx_parse_offset(ngx_str_t *line);
2017 ngx_int_t ngx_parse_time(ngx_str_t *line, ngx_uint_t is_sec);
159159
160160 r->valid = ngx_parse_time(&s, 1);
161161
162 if (r->valid == NGX_ERROR) {
162 if (r->valid == (time_t) NGX_ERROR) {
163163 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
164164 "invalid parameter: %V", &names[i]);
165165 return NULL;
529529
530530 hcf->expires_time = ngx_parse_time(&value[n], 1);
531531
532 if (hcf->expires_time == NGX_ERROR) {
532 if (hcf->expires_time == (time_t) NGX_ERROR) {
533533 return "invalid value";
534534 }
535535
537537 && hcf->expires_time > 24 * 60 * 60)
538538 {
539539 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";
544540 }
545541
546542 if (minus) {
12481248 s.data = value[i].data + 9;
12491249
12501250 inactive = ngx_parse_time(&s, 1);
1251 if (inactive < 0) {
1251 if (inactive == (time_t) NGX_ERROR) {
12521252 goto failed;
12531253 }
12541254
12711271 s.data = value[i].data + 6;
12721272
12731273 valid = ngx_parse_time(&s, 1);
1274 if (valid < 0) {
1274 if (valid == (time_t) NGX_ERROR) {
12751275 goto failed;
12761276 }
12771277
773773 }
774774
775775 ucf->expires = ngx_parse_time(&value[1], 1);
776 if (ucf->expires == NGX_ERROR) {
776 if (ucf->expires == (time_t) NGX_ERROR) {
777777 return "invalid value";
778 }
779
780 if (ucf->expires == NGX_PARSE_LARGE_TIME) {
781 return "value must be less than 68 years";
782778 }
783779
784780 return NGX_CONF_OK;
273273 line.data = value[i].data + 2;
274274
275275 bl->timeout = ngx_parse_time(&line, 1);
276 if (bl->timeout == NGX_ERROR) {
276 if (bl->timeout == (time_t) NGX_ERROR) {
277277 invalid = 1;
278278 break;
279279 }
38523852 s.len = p - s.data;
38533853
38543854 lsopt.tcp_keepidle = ngx_parse_time(&s, 1);
3855 if (lsopt.tcp_keepidle == NGX_ERROR) {
3855 if (lsopt.tcp_keepidle == (time_t) NGX_ERROR) {
38563856 goto invalid_so_keepalive;
38573857 }
38583858 }
38683868 s.len = p - s.data;
38693869
38703870 lsopt.tcp_keepintvl = ngx_parse_time(&s, 1);
3871 if (lsopt.tcp_keepintvl == NGX_ERROR) {
3871 if (lsopt.tcp_keepintvl == (time_t) NGX_ERROR) {
38723872 goto invalid_so_keepalive;
38733873 }
38743874 }
45154515 s.data = value[i].data + 9;
45164516
45174517 inactive = ngx_parse_time(&s, 1);
4518 if (inactive < 0) {
4518 if (inactive == (time_t) NGX_ERROR) {
45194519 goto failed;
45204520 }
45214521
46024602 return "invalid value";
46034603 }
46044604
4605 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
4606 return "value must be less than 597 hours";
4607 }
4608
46094605 if (cf->args->nelts == 2) {
46104606 return NGX_CONF_OK;
46114607 }
46124608
46134609 clcf->keepalive_header = ngx_parse_time(&value[2], 1);
46144610
4615 if (clcf->keepalive_header == NGX_ERROR) {
4611 if (clcf->keepalive_header == (time_t) NGX_ERROR) {
46164612 return "invalid value";
4617 }
4618
4619 if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
4620 return "value must be less than 68 years";
46214613 }
46224614
46234615 return NGX_CONF_OK;
15961596 time_t inactive;
15971597 ssize_t size;
15981598 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;
16001601 ngx_uint_t i, n;
16011602 ngx_http_file_cache_t *cache;
16021603
17031704 s.data = value[i].data + 9;
17041705
17051706 inactive = ngx_parse_time(&s, 1);
1706 if (inactive < 0) {
1707 if (inactive == (time_t) NGX_ERROR) {
17071708 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
17081709 "invalid inactive value \"%V\"", &value[i]);
17091710 return NGX_CONF_ERROR;
17451746 s.data = value[i].data + 13;
17461747
17471748 loader_sleep = ngx_parse_time(&s, 0);
1748 if (loader_sleep < 0) {
1749 if (loader_sleep == (ngx_msec_t) NGX_ERROR) {
17491750 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
17501751 "invalid loader_sleep value \"%V\"", &value[i]);
17511752 return NGX_CONF_ERROR;
17601761 s.data = value[i].data + 17;
17611762
17621763 loader_threshold = ngx_parse_time(&s, 0);
1763 if (loader_threshold < 0) {
1764 if (loader_threshold == (ngx_msec_t) NGX_ERROR) {
17641765 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
17651766 "invalid loader_threshold value \"%V\"", &value[i]);
17661767 return NGX_CONF_ERROR;
17871788 cache->path->conf_file = cf->conf_file->file.name.data;
17881789 cache->path->line = cf->conf_file->line;
17891790 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;
17921793
17931794 if (ngx_add_path(cf, &cache->path) != NGX_OK) {
17941795 return NGX_CONF_ERROR;
18421843 n = cf->args->nelts - 1;
18431844
18441845 valid = ngx_parse_time(&value[n], 1);
1845 if (valid < 0) {
1846 if (valid == (time_t) NGX_ERROR) {
18461847 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
18471848 "invalid time value \"%V\"", &value[n]);
18481849 return NGX_CONF_ERROR;
42674267
42684268 fail_timeout = ngx_parse_time(&s, 1);
42694269
4270 if (fail_timeout == NGX_ERROR) {
4270 if (fail_timeout == (time_t) NGX_ERROR) {
42714271 goto invalid;
42724272 }
42734273
478478 s.len = p - s.data;
479479
480480 ls->tcp_keepidle = ngx_parse_time(&s, 1);
481 if (ls->tcp_keepidle == NGX_ERROR) {
481 if (ls->tcp_keepidle == (time_t) NGX_ERROR) {
482482 goto invalid_so_keepalive;
483483 }
484484 }
494494 s.len = p - s.data;
495495
496496 ls->tcp_keepintvl = ngx_parse_time(&s, 1);
497 if (ls->tcp_keepintvl == NGX_ERROR) {
497 if (ls->tcp_keepintvl == (time_t) NGX_ERROR) {
498498 goto invalid_so_keepalive;
499499 }
500500 }