[PATCH 03 of 31] Bugfix: https wasn't working on systems with 32-bit off_t

Maxim Dounin mdounin at mdounin.ru
Mon Jun 27 21:06:33 MSD 2011


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1309178044 -14400
# Node ID 8cde8b1630d8e84d692477ec7f3ee7a54c45fb23
# Parent  8a0c9f46d6d87364922d2db80a1cc7538a8fd028
Bugfix: https wasn't working on systems with 32-bit off_t.

Due to off_t being signed NGX_MAX_UINT32_VALUE will overflow off_t while
calculating limit in ngx_ssl_send_chain() on systems with 32-bit off_t,
and as a result ngx_ssl_send_chain() won't be able to send anything.

Introduce NGX_MAX_INT32_VALUE and use it there instead.

diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -127,5 +127,6 @@ typedef intptr_t        ngx_flag_t;
 #define NGX_MAX_UINT32_VALUE  (uint32_t) 0xffffffff
 #endif
 
+#define NGX_MAX_INT32_VALUE   (int32_t) 2147483647
 
 #endif /* _NGX_CONFIG_H_INCLUDED_ */
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -957,10 +957,10 @@ ngx_ssl_send_chain(ngx_connection_t *c, 
     }
 
 
-    /* the maximum limit size is the maximum uint32_t value - the page size */
-
-    if (limit == 0 || limit > (off_t) (NGX_MAX_UINT32_VALUE - ngx_pagesize)) {
-        limit = NGX_MAX_UINT32_VALUE - ngx_pagesize;
+    /* the maximum limit size is the maximum int32_t value - the page size */
+
+    if (limit == 0 || limit > (off_t) (NGX_MAX_INT32_VALUE - ngx_pagesize)) {
+        limit = NGX_MAX_INT32_VALUE - ngx_pagesize;
     }
 
     buf = c->ssl->buf;



More information about the nginx-devel mailing list