]> git.kaiwu.me - nginx.git/commitdiff
Geo: fixed access to already freed memory.
authorValentin Bartenev <vbart@nginx.com>
Thu, 18 Aug 2016 14:11:03 +0000 (17:11 +0300)
committerValentin Bartenev <vbart@nginx.com>
Thu, 18 Aug 2016 14:11:03 +0000 (17:11 +0300)
Previously, in "ranges" mode when all added ranges were deleted,
the ctx.high.low[i] was left pointing to a temporary array.

src/http/modules/ngx_http_geo_module.c
src/stream/ngx_stream_geo_module.c

index 9b3c6cb9ceaf412ecff2795034fc7d621d70bbd9..53e89692dae3cdbbc1ed9ab73cd51b01a6cbfb32 100644 (file)
@@ -469,7 +469,12 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
             for (i = 0; i < 0x10000; i++) {
                 a = (ngx_array_t *) ctx.high.low[i];
 
-                if (a == NULL || a->nelts == 0) {
+                if (a == NULL) {
+                    continue;
+                }
+
+                if (a->nelts == 0) {
+                    ctx.high.low[i] = NULL;
                     continue;
                 }
 
index ed1a4886b174faf5a9b6f74d5eb349bf8e918d0e..32fb9c0f4f3b4d938fa74a9fb761ff35109d15e4 100644 (file)
@@ -436,7 +436,12 @@ ngx_stream_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
             for (i = 0; i < 0x10000; i++) {
                 a = (ngx_array_t *) ctx.high.low[i];
 
-                if (a == NULL || a->nelts == 0) {
+                if (a == NULL) {
+                    continue;
+                }
+
+                if (a->nelts == 0) {
+                    ctx.high.low[i] = NULL;
                     continue;
                 }