src/http/ngx_http_upstream_round_robin.c:188: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned64.

src/http/ngx_http_upstream_round_robin.c:176:9: <LHS trace>
174.     u.port = (in_port_t) (us->port ? us->port : us->default_port);
175. 
176.     if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
             ^
177.         if (u.err) {
178.             ngx_log_error(NGX_LOG_EMERG, cf->log, 0,

src/http/ngx_http_upstream_round_robin.c:176:9: Call
174.     u.port = (in_port_t) (us->port ? us->port : us->default_port);
175. 
176.     if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
             ^
177.         if (u.err) {
178.             ngx_log_error(NGX_LOG_EMERG, cf->log, 0,

src/core/ngx_inet.c:1081:1: Parameter `u->naddrs`
  1079. #else /* !NGX_HAVE_GETADDRINFO || !NGX_HAVE_INET6 */
  1080. 
  1081. ngx_int_t
        ^
  1082. ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
  1083. {

src/http/ngx_http_upstream_round_robin.c:186:5: Assignment
184.     }
185. 
186.     n = u.naddrs;
         ^
187. 
188.     peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)

src/http/ngx_http_upstream_round_robin.c:188:13: Binary operation: ([0, +oo] - 1):unsigned64
186.     n = u.naddrs;
187. 
188.     peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)
                 ^
189.                               + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));
190.     if (peers == NULL) {

ngx_int_t
ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
    ngx_http_upstream_srv_conf_t *us)
{
    ngx_url_t                      u;
    ngx_uint_t                     i, j, n, w;
    ngx_http_upstream_server_t    *server;
    ngx_http_upstream_rr_peers_t  *peers, *backup;
    us->peer.init = ngx_http_upstream_init_round_robin_peer;
    if (us->servers) {
        server = us->servers->elts;
        n = 0;
        w = 0;
        for (i = 0; i < us->servers->nelts; i++) {
            if (server[i].backup) {
                continue;
            }
            n += server[i].naddrs;
            w += server[i].naddrs * server[i].weight;
        }
        if (n == 0) {
            ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                          "no servers in upstream \"%V\" in %s:%ui",
                          &us->host, us->file_name, us->line);
            return NGX_ERROR;
        }
        peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)
                              + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));
        if (peers == NULL) {
            return NGX_ERROR;
        }
        peers->single = (n == 1);
        peers->number = n;
        peers->weighted = (w != n);
        peers->total_weight = w;
        peers->name = &us->host;
        n = 0;
        for (i = 0; i < us->servers->nelts; i++) {
            for (j = 0; j < server[i].naddrs; j++) {
                if (server[i].backup) {
                    continue;
                }
                peers->peer[n].sockaddr = server[i].addrs[j].sockaddr;
                peers->peer[n].socklen = server[i].addrs[j].socklen;
                peers->peer[n].name = server[i].addrs[j].name;
                peers->peer[n].max_fails = server[i].max_fails;
                peers->peer[n].fail_timeout = server[i].fail_timeout;
                peers->peer[n].down = server[i].down;
                peers->peer[n].weight = server[i].weight;
                peers->peer[n].effective_weight = server[i].weight;
                peers->peer[n].current_weight = 0;
                n++;
            }
        }
        us->peer.data = peers;
        ngx_sort(&peers->peer[0], (size_t) n,
                 sizeof(ngx_http_upstream_rr_peer_t),
                 ngx_http_upstream_cmp_servers);
        n = 0;
        w = 0;
        for (i = 0; i < us->servers->nelts; i++) {
            if (!server[i].backup) {
                continue;
            }
            n += server[i].naddrs;
            w += server[i].naddrs * server[i].weight;
        }
        if (n == 0) {
            return NGX_OK;
        }
        backup = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)
                              + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));
        if (backup == NULL) {
            return NGX_ERROR;
        }
        peers->single = 0;
        backup->single = 0;
        backup->number = n;
        backup->weighted = (w != n);
        backup->total_weight = w;
        backup->name = &us->host;
        n = 0;
        for (i = 0; i < us->servers->nelts; i++) {
            for (j = 0; j < server[i].naddrs; j++) {
                if (!server[i].backup) {
                    continue;
                }
                backup->peer[n].sockaddr = server[i].addrs[j].sockaddr;
                backup->peer[n].socklen = server[i].addrs[j].socklen;
                backup->peer[n].name = server[i].addrs[j].name;
                backup->peer[n].weight = server[i].weight;
                backup->peer[n].effective_weight = server[i].weight;
                backup->peer[n].current_weight = 0;
                backup->peer[n].max_fails = server[i].max_fails;
                backup->peer[n].fail_timeout = server[i].fail_timeout;
                backup->peer[n].down = server[i].down;
                n++;
            }
        }
        peers->next = backup;
        ngx_sort(&backup->peer[0], (size_t) n,
                 sizeof(ngx_http_upstream_rr_peer_t),
                 ngx_http_upstream_cmp_servers);
        return NGX_OK;
    }
    if (us->port == 0 && us->default_port == 0) {
        ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                      "no port in upstream \"%V\" in %s:%ui",
                      &us->host, us->file_name, us->line);
        return NGX_ERROR;
    }
    ngx_memzero(&u, sizeof(ngx_url_t));
    u.host = us->host;
    u.port = (in_port_t) (us->port ? us->port : us->default_port);
    if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
        if (u.err) {
            ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                          "%s in upstream \"%V\" in %s:%ui",
                          u.err, &us->host, us->file_name, us->line);
        }
        return NGX_ERROR;
    }
    n = u.naddrs;
    peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)
                              + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));
    if (peers == NULL) {
        return NGX_ERROR;
    }
    peers->single = (n == 1);
    peers->number = n;
    peers->weighted = 0;
    peers->total_weight = n;
    peers->name = &us->host;
    for (i = 0; i < u.naddrs; i++) {
        peers->peer[i].sockaddr = u.addrs[i].sockaddr;
        peers->peer[i].socklen = u.addrs[i].socklen;
        peers->peer[i].name = u.addrs[i].name;
        peers->peer[i].weight = 1;
        peers->peer[i].effective_weight = 1;
        peers->peer[i].current_weight = 0;
        peers->peer[i].max_fails = 1;
        peers->peer[i].fail_timeout = 10;
    }
    us->peer.data = peers;
    return NGX_OK;
}
['ngx_int_t\nngx_http_upstream_init_round_robin(ngx_conf_t *cf,\n    ngx_http_upstream_srv_conf_t *us)\n{\n    ngx_url_t                      u;\n    ngx_uint_t                     i, j, n, w;\n    ngx_http_upstream_server_t    *server;\n    ngx_http_upstream_rr_peers_t  *peers, *backup;\n    us->peer.init = ngx_http_upstream_init_round_robin_peer;\n    if (us->servers) {\n        server = us->servers->elts;\n        n = 0;\n        w = 0;\n        for (i = 0; i < us->servers->nelts; i++) {\n            if (server[i].backup) {\n                continue;\n            }\n            n += server[i].naddrs;\n            w += server[i].naddrs * server[i].weight;\n        }\n        if (n == 0) {\n            ngx_log_error(NGX_LOG_EMERG, cf->log, 0,\n                          "no servers in upstream \\"%V\\" in %s:%ui",\n                          &us->host, us->file_name, us->line);\n            return NGX_ERROR;\n        }\n        peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)\n                              + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));\n        if (peers == NULL) {\n            return NGX_ERROR;\n        }\n        peers->single = (n == 1);\n        peers->number = n;\n        peers->weighted = (w != n);\n        peers->total_weight = w;\n        peers->name = &us->host;\n        n = 0;\n        for (i = 0; i < us->servers->nelts; i++) {\n            for (j = 0; j < server[i].naddrs; j++) {\n                if (server[i].backup) {\n                    continue;\n                }\n                peers->peer[n].sockaddr = server[i].addrs[j].sockaddr;\n                peers->peer[n].socklen = server[i].addrs[j].socklen;\n                peers->peer[n].name = server[i].addrs[j].name;\n                peers->peer[n].max_fails = server[i].max_fails;\n                peers->peer[n].fail_timeout = server[i].fail_timeout;\n                peers->peer[n].down = server[i].down;\n                peers->peer[n].weight = server[i].weight;\n                peers->peer[n].effective_weight = server[i].weight;\n                peers->peer[n].current_weight = 0;\n                n++;\n            }\n        }\n        us->peer.data = peers;\n        ngx_sort(&peers->peer[0], (size_t) n,\n                 sizeof(ngx_http_upstream_rr_peer_t),\n                 ngx_http_upstream_cmp_servers);\n        n = 0;\n        w = 0;\n        for (i = 0; i < us->servers->nelts; i++) {\n            if (!server[i].backup) {\n                continue;\n            }\n            n += server[i].naddrs;\n            w += server[i].naddrs * server[i].weight;\n        }\n        if (n == 0) {\n            return NGX_OK;\n        }\n        backup = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)\n                              + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));\n        if (backup == NULL) {\n            return NGX_ERROR;\n        }\n        peers->single = 0;\n        backup->single = 0;\n        backup->number = n;\n        backup->weighted = (w != n);\n        backup->total_weight = w;\n        backup->name = &us->host;\n        n = 0;\n        for (i = 0; i < us->servers->nelts; i++) {\n            for (j = 0; j < server[i].naddrs; j++) {\n                if (!server[i].backup) {\n                    continue;\n                }\n                backup->peer[n].sockaddr = server[i].addrs[j].sockaddr;\n                backup->peer[n].socklen = server[i].addrs[j].socklen;\n                backup->peer[n].name = server[i].addrs[j].name;\n                backup->peer[n].weight = server[i].weight;\n                backup->peer[n].effective_weight = server[i].weight;\n                backup->peer[n].current_weight = 0;\n                backup->peer[n].max_fails = server[i].max_fails;\n                backup->peer[n].fail_timeout = server[i].fail_timeout;\n                backup->peer[n].down = server[i].down;\n                n++;\n            }\n        }\n        peers->next = backup;\n        ngx_sort(&backup->peer[0], (size_t) n,\n                 sizeof(ngx_http_upstream_rr_peer_t),\n                 ngx_http_upstream_cmp_servers);\n        return NGX_OK;\n    }\n    if (us->port == 0 && us->default_port == 0) {\n        ngx_log_error(NGX_LOG_EMERG, cf->log, 0,\n                      "no port in upstream \\"%V\\" in %s:%ui",\n                      &us->host, us->file_name, us->line);\n        return NGX_ERROR;\n    }\n    ngx_memzero(&u, sizeof(ngx_url_t));\n    u.host = us->host;\n    u.port = (in_port_t) (us->port ? us->port : us->default_port);\n    if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {\n        if (u.err) {\n            ngx_log_error(NGX_LOG_EMERG, cf->log, 0,\n                          "%s in upstream \\"%V\\" in %s:%ui",\n                          u.err, &us->host, us->file_name, us->line);\n        }\n        return NGX_ERROR;\n    }\n    n = u.naddrs;\n    peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)\n                              + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));\n    if (peers == NULL) {\n        return NGX_ERROR;\n    }\n    peers->single = (n == 1);\n    peers->number = n;\n    peers->weighted = 0;\n    peers->total_weight = n;\n    peers->name = &us->host;\n    for (i = 0; i < u.naddrs; i++) {\n        peers->peer[i].sockaddr = u.addrs[i].sockaddr;\n        peers->peer[i].socklen = u.addrs[i].socklen;\n        peers->peer[i].name = u.addrs[i].name;\n        peers->peer[i].weight = 1;\n        peers->peer[i].effective_weight = 1;\n        peers->peer[i].current_weight = 0;\n        peers->peer[i].max_fails = 1;\n        peers->peer[i].fail_timeout = 10;\n    }\n    us->peer.data = peers;\n    return NGX_OK;\n}', 'ngx_int_t\nngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)\n{\n    u_char              *p, *host;\n    size_t               len;\n    in_port_t            port;\n    in_addr_t            in_addr;\n    ngx_uint_t           i;\n    struct hostent      *h;\n    struct sockaddr_in  *sin;\n    port = htons(u->port);\n    in_addr = ngx_inet_addr(u->host.data, u->host.len);\n    if (in_addr == INADDR_NONE) {\n        host = ngx_alloc(u->host.len + 1, pool->log);\n        if (host == NULL) {\n            return NGX_ERROR;\n        }\n        (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);\n        h = gethostbyname((char *) host);\n        ngx_free(host);\n        if (h == NULL || h->h_addr_list[0] == NULL) {\n            u->err = "host not found";\n            return NGX_ERROR;\n        }\n        for (i = 0; h->h_addr_list[i] != NULL; i++) {   }\n        u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t));\n        if (u->addrs == NULL) {\n            return NGX_ERROR;\n        }\n        u->naddrs = i;\n        for (i = 0; i < u->naddrs; i++) {\n            sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));\n            if (sin == NULL) {\n                return NGX_ERROR;\n            }\n            sin->sin_family = AF_INET;\n            sin->sin_port = port;\n            sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]);\n            u->addrs[i].sockaddr = (struct sockaddr *) sin;\n            u->addrs[i].socklen = sizeof(struct sockaddr_in);\n            len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1;\n            p = ngx_pnalloc(pool, len);\n            if (p == NULL) {\n                return NGX_ERROR;\n            }\n            len = ngx_sock_ntop((struct sockaddr *) sin, p, len, 1);\n            u->addrs[i].name.len = len;\n            u->addrs[i].name.data = p;\n        }\n    } else {\n        u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));\n        if (u->addrs == NULL) {\n            return NGX_ERROR;\n        }\n        sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));\n        if (sin == NULL) {\n            return NGX_ERROR;\n        }\n        u->naddrs = 1;\n        sin->sin_family = AF_INET;\n        sin->sin_port = port;\n        sin->sin_addr.s_addr = in_addr;\n        u->addrs[0].sockaddr = (struct sockaddr *) sin;\n        u->addrs[0].socklen = sizeof(struct sockaddr_in);\n        p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1);\n        if (p == NULL) {\n            return NGX_ERROR;\n        }\n        u->addrs[0].name.len = ngx_sprintf(p, "%V:%d",\n                                           &u->host, ntohs(port)) - p;\n        u->addrs[0].name.data = p;\n    }\n    return NGX_OK;\n}']