Welcome! Log In Create A New Profile

Advanced

[PATCH 25 of 25] Time parsing cleanup

Maxim Dounin
September 06, 2011 12:14PM
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1315324516 -14400
# Node ID 6d7dc429ad2bbb9ffe095fe970f0c6c7b8242397
# Parent bace4194977872078bfa7586303dc3565cda481a
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).

diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -1294,10 +1294,6 @@ ngx_conf_set_msec_slot(ngx_conf_t *cf, n
return "invalid value";
}

- if (*msp == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
- return "value must be less than 597 hours";
- }
-
if (cmd->post) {
post = cmd->post;
return post->post_handler(cf, post, msp);
@@ -1325,14 +1321,10 @@ ngx_conf_set_sec_slot(ngx_conf_t *cf, ng
value = cf->args->elts;

*sp = ngx_parse_time(&value[1], 1);
- if (*sp == NGX_ERROR) {
+ if (*sp == (time_t) NGX_ERROR) {
return "invalid value";
}

- if (*sp == NGX_PARSE_LARGE_TIME) {
- return "value must be less than 68 years";
- }
-
if (cmd->post) {
post = cmd->post;
return post->post_handler(cf, post, sp);
diff --git a/src/core/ngx_parse.h b/src/core/ngx_parse.h
--- a/src/core/ngx_parse.h
+++ b/src/core/ngx_parse.h
@@ -12,9 +12,6 @@
#include <ngx_core.h>


-#define NGX_PARSE_LARGE_TIME -2
-
-
ssize_t ngx_parse_size(ngx_str_t *line);
off_t ngx_parse_offset(ngx_str_t *line);
ngx_int_t ngx_parse_time(ngx_str_t *line, ngx_uint_t sec);
diff --git a/src/http/modules/ngx_http_headers_filter_module.c b/src/http/modules/ngx_http_headers_filter_module.c
--- a/src/http/modules/ngx_http_headers_filter_module.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -531,7 +531,7 @@ ngx_http_headers_expires(ngx_conf_t *cf,

hcf->expires_time = ngx_parse_time(&value[n], 1);

- if (hcf->expires_time == NGX_ERROR) {
+ if (hcf->expires_time == (time_t) NGX_ERROR) {
return "invalid value";
}

@@ -541,10 +541,6 @@ ngx_http_headers_expires(ngx_conf_t *cf,
return "daily time value must be less than 24 hours";
}

- if (hcf->expires_time == NGX_PARSE_LARGE_TIME) {
- return "value must be less than 68 years";
- }
-
if (minus) {
hcf->expires_time = - hcf->expires_time;
}
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -1242,7 +1242,7 @@ ngx_http_log_open_file_cache(ngx_conf_t
s.data = value[i].data + 9;

inactive = ngx_parse_time(&s, 1);
- if (inactive < 0) {
+ if (inactive == (time_t) NGX_ERROR) {
goto failed;
}

@@ -1265,7 +1265,7 @@ ngx_http_log_open_file_cache(ngx_conf_t
s.data = value[i].data + 6;

valid = ngx_parse_time(&s, 1);
- if (valid < 0) {
+ if (valid == (time_t) NGX_ERROR) {
goto failed;
}

diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c
--- a/src/http/modules/ngx_http_userid_filter_module.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -773,14 +773,10 @@ ngx_http_userid_expires(ngx_conf_t *cf,
}

ucf->expires = ngx_parse_time(&value[1], 1);
- if (ucf->expires == NGX_ERROR) {
+ if (ucf->expires == (time_t) NGX_ERROR) {
return "invalid value";
}

- if (ucf->expires == NGX_PARSE_LARGE_TIME) {
- return "value must be less than 68 years";
- }
-
return NGX_CONF_OK;
}

diff --git a/src/http/ngx_http_busy_lock.c b/src/http/ngx_http_busy_lock.c
--- a/src/http/ngx_http_busy_lock.c
+++ b/src/http/ngx_http_busy_lock.c
@@ -273,7 +273,7 @@ char *ngx_http_set_busy_lock_slot(ngx_co
line.data = value[i].data + 2;

bl->timeout = ngx_parse_time(&line, 1);
- if (bl->timeout == NGX_ERROR) {
+ if (bl->timeout == (time_t) NGX_ERROR) {
invalid = 1;
break;
}
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -4418,7 +4418,7 @@ ngx_http_core_open_file_cache(ngx_conf_t
s.data = value[i].data + 9;

inactive = ngx_parse_time(&s, 1);
- if (inactive < 0) {
+ if (inactive == (time_t) NGX_ERROR) {
goto failed;
}

@@ -4505,24 +4505,16 @@ ngx_http_core_keepalive(ngx_conf_t *cf,
return "invalid value";
}

- if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
- return "value must be less than 597 hours";
- }
-
if (cf->args->nelts == 2) {
return NGX_CONF_OK;
}

clcf->keepalive_header = ngx_parse_time(&value[2], 1);

- if (clcf->keepalive_header == NGX_ERROR) {
+ if (clcf->keepalive_header == (time_t) NGX_ERROR) {
return "invalid value";
}

- if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
- return "value must be less than 68 years";
- }
-
return NGX_CONF_OK;
}

diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -1458,7 +1458,8 @@ ngx_http_file_cache_set_slot(ngx_conf_t
time_t inactive;
ssize_t size;
ngx_str_t s, name, *value;
- ngx_int_t loader_files, loader_sleep, loader_threshold;
+ ngx_int_t loader_files;
+ ngx_msec_t loader_sleep, loader_threshold;
ngx_uint_t i, n;
ngx_http_file_cache_t *cache;

@@ -1565,7 +1566,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t
s.data = value[i].data + 9;

inactive = ngx_parse_time(&s, 1);
- if (inactive < 0) {
+ if (inactive == (time_t) NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid inactive value \"%V\"", &value[i]);
return NGX_CONF_ERROR;
@@ -1607,7 +1608,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t
s.data = value[i].data + 13;

loader_sleep = ngx_parse_time(&s, 0);
- if (loader_sleep < 0) {
+ if (loader_sleep == (ngx_msec_t) NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid loader_sleep value \"%V\"", &value[i]);
return NGX_CONF_ERROR;
@@ -1622,7 +1623,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t
s.data = value[i].data + 17;

loader_threshold = ngx_parse_time(&s, 0);
- if (loader_threshold < 0) {
+ if (loader_threshold == (ngx_msec_t) NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid loader_threshold value \"%V\"", &value[i]);
return NGX_CONF_ERROR;
@@ -1649,8 +1650,8 @@ ngx_http_file_cache_set_slot(ngx_conf_t
cache->path->conf_file = cf->conf_file->file.name.data;
cache->path->line = cf->conf_file->line;
cache->loader_files = loader_files;
- cache->loader_sleep = (ngx_msec_t) loader_sleep;
- cache->loader_threshold = (ngx_msec_t) loader_threshold;
+ cache->loader_sleep = loader_sleep;
+ cache->loader_threshold = loader_threshold;

if (ngx_add_path(cf, &cache->path) != NGX_OK) {
return NGX_CONF_ERROR;
@@ -1704,7 +1705,7 @@ ngx_http_file_cache_valid_set_slot(ngx_c
n = cf->args->nelts - 1;

valid = ngx_parse_time(&value[n], 1);
- if (valid < 0) {
+ if (valid == (time_t) NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid time value \"%V\"", &value[n]);
return NGX_CONF_ERROR;
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -4163,7 +4163,7 @@ ngx_http_upstream_server(ngx_conf_t *cf,

fail_timeout = ngx_parse_time(&s, 1);

- if (fail_timeout == NGX_ERROR) {
+ if (fail_timeout == (time_t) NGX_ERROR) {
goto invalid;
}


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 00 of 25] generic patch queue

Maxim Dounin 1698 September 06, 2011 12:10PM

[PATCH 01 of 25] Handling of If-Range with add_header Last-Modified

Maxim Dounin 715 September 06, 2011 12:10PM

[PATCH 02 of 25] Fix for incorrect 201 replies from dav module

Maxim Dounin 726 September 06, 2011 12:10PM

[PATCH 03 of 25] Fix for double content when return is used in error_page handler

Maxim Dounin 695 September 06, 2011 12:10PM

[PATCH 04 of 25] Fix for "return 202" not discarding body

Maxim Dounin 685 September 06, 2011 12:10PM

[PATCH 05 of 25] Incorrect special case for "return 204" removed

Maxim Dounin 677 September 06, 2011 12:10PM

[PATCH 06 of 25] Clear old Location header (if any) while adding new one

Maxim Dounin 735 September 06, 2011 12:10PM

[PATCH 07 of 25] Better handling of late upstream creation

Maxim Dounin 777 September 06, 2011 12:10PM

[PATCH 08 of 25] Gzip filter: handle empty flush buffers

Maxim Dounin 751 September 06, 2011 12:12PM

[PATCH 09 of 25] Fix for connection drops with AIO

Maxim Dounin 686 September 06, 2011 12:12PM

[PATCH 10 of 25] Fix for socket leak with "aio sendfile" and "limit_rate"

Maxim Dounin 748 September 06, 2011 12:12PM

[PATCH 11 of 25] Handling of Content-Encoding set from perl

Maxim Dounin 709 September 06, 2011 12:12PM

[PATCH 12 of 25] Gzip static: "always" parameter in "gzip_static" directive

Maxim Dounin 687 September 06, 2011 12:12PM

[PATCH 13 of 25] Memcached: memcached_gzip_flag directive

Maxim Dounin 806 September 06, 2011 12:12PM

[PATCH 14 of 25] Mail: handle smtp multiline replies

Maxim Dounin 643 September 06, 2011 12:12PM

[PATCH 15 of 25] Additional headers for proxy_ignore_headers/fastcgi_ignore_headers

Maxim Dounin 727 September 06, 2011 12:12PM

[PATCH 16 of 25] Fix for proxy_store leaving temporary files for subrequests

Maxim Dounin 770 September 06, 2011 12:12PM

[PATCH 17 of 25] Cache: fix for sending of empty responses

Maxim Dounin 656 September 06, 2011 12:12PM

[PATCH 18 of 25] Cache: fix for sending of stale responses

Maxim Dounin 808 September 06, 2011 12:14PM

[PATCH 19 of 25] Variables: honor no_cacheable for not_found variables

Maxim Dounin 789 September 06, 2011 12:14PM

[PATCH 20 of 25] Core: protection from subrequest loops

Maxim Dounin 692 September 06, 2011 12:14PM

[PATCH 21 of 25] Core: protection from cycles with named locations and post_action

Maxim Dounin 715 September 06, 2011 12:14PM

[PATCH 22 of 25] Autoindex: escape '?' in file names

Maxim Dounin 793 September 06, 2011 12:14PM

[PATCH 23 of 25] Autoindex: escape html in file names

Maxim Dounin 786 September 06, 2011 12:14PM

[PATCH 24 of 25] Unbreak build with embedded perl and --with-openssl

Maxim Dounin 827 September 06, 2011 12:14PM

[PATCH 25 of 25] Time parsing cleanup

Maxim Dounin 786 September 06, 2011 12:14PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 223
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready