]> git.kaiwu.me - nginx.git/commitdiff
Fixed lingering_time check.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 13 May 2013 13:39:45 +0000 (17:39 +0400)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 13 May 2013 13:39:45 +0000 (17:39 +0400)
There are two significant changes in this patch:

1) The <= 0 comparison is done with a signed type.  This fixes the case
   of ngx_time() being larger than r->lingering_time.

2) Calculation of r->lingering_time - ngx_time() is now always done
   in the ngx_msec_t type.  This ensures the calculation is correct
   even if time_t is unsigned and differs in size from ngx_msec_t.

Thanks to Lanshun Zhou.

src/http/ngx_http_request.c
src/http/ngx_http_request_body.c

index c8c5d153f3798dfefaf510a321d0192ff97e4dec..64f31b2c3964fda76687ecbbb71165e2d2178ba1 100644 (file)
@@ -3166,8 +3166,8 @@ ngx_http_lingering_close_handler(ngx_event_t *rev)
         return;
     }
 
-    timer = (ngx_msec_t) (r->lingering_time - ngx_time());
-    if (timer <= 0) {
+    timer = (ngx_msec_t) r->lingering_time - (ngx_msec_t) ngx_time();
+    if ((ngx_msec_int_t) timer <= 0) {
         ngx_http_close_request(r, 0);
         return;
     }
index 7ca328791fe5fc10ff97628332b3b11645568cc2..fc3a1800df03f29f143538ce9bce0f5eb5287bc4 100644 (file)
@@ -570,9 +570,9 @@ ngx_http_discarded_request_body_handler(ngx_http_request_t *r)
     }
 
     if (r->lingering_time) {
-        timer = (ngx_msec_t) (r->lingering_time - ngx_time());
+        timer = (ngx_msec_t) r->lingering_time - (ngx_msec_t) ngx_time();
 
-        if (timer <= 0) {
+        if ((ngx_msec_int_t) timer <= 0) {
             r->discard_body = 0;
             r->lingering_close = 0;
             ngx_http_finalize_request(r, NGX_ERROR);