]> git.kaiwu.me - nginx.git/commitdiff
Core: fixed potential division by zero when initializing hash.
authorSergey Kandaurov <pluknet@nginx.com>
Thu, 13 Aug 2015 13:27:17 +0000 (16:27 +0300)
committerSergey Kandaurov <pluknet@nginx.com>
Thu, 13 Aug 2015 13:27:17 +0000 (16:27 +0300)
Found by Clang Static Analyzer.

src/core/ngx_hash.c

index e58156d55633a6c9c83557d98f479ea6fdf27d4d..1a5d0be2efe8faa5a0a06706a5e58ef4761ee494 100644 (file)
@@ -257,6 +257,14 @@ ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts)
     ngx_uint_t       i, n, key, size, start, bucket_size;
     ngx_hash_elt_t  *elt, **buckets;
 
+    if (hinit->max_size == 0) {
+        ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0,
+                      "could not build %s, you should "
+                      "increase %s_max_size: %i",
+                      hinit->name, hinit->name, hinit->max_size);
+        return NGX_ERROR;
+    }
+
     for (n = 0; n < nelts; n++) {
         if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *))
         {