Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile at gcc version: 4.7.2 with cc-opt=-O3 #383

Closed
magicbear opened this issue Jan 11, 2014 · 5 comments
Closed

Cannot compile at gcc version: 4.7.2 with cc-opt=-O3 #383

magicbear opened this issue Jan 11, 2014 · 5 comments

Comments

@magicbear
Copy link
Contributor

Cannot compile at gcc version: 4.7.2 (Debian 4.7.2-5)
./configure --with-cc-opt=-O3 && make
src/http/ngx_http_request.c: In function ‘ngx_http_set_virtual_server’:
src/http/ngx_http_request.c:2109:32: error: ‘cscf’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

@yaoweibin
Copy link
Member

Smart compile! It seems the problem is in ngx_http_find_virtual_server, could you help us to fix this bug?

@magicbear
Copy link
Contributor Author

I had reviews the code for ngx_http_find_virtual_server, it seems works fine. But I dont know why it will cause fail.
The most easy way to fix it is

--- a/src/http/ngx_http_request.c 2014-01-08 20:24:46.000000000 +0800
+++ b/src/http/ngx_http_request.c 2014-01-12 02:49:03.757373929 +0800
@@ -2106,7 +2106,7 @@ ngx_http_set_virtual_server(ngx_http_req
ngx_int_t rc;
ngx_http_connection_t *hc;
ngx_http_core_loc_conf_t *clcf;

  • ngx_http_core_srv_conf_t *cscf;
  • ngx_http_core_srv_conf_t *cscf = NULL;

hc = r->http_connection;

But I think this fix way is incorrent, so I haven't commit it.

@yaoweibin
Copy link
Member

In the function ngx_http_find_virtual_server, it will return NGX_DECLINDE when virtual_names is NULL. At that time, cscf is unintialized.

@magicbear
Copy link
Contributor Author

Here is the code after preprocess
after ngx_http_find_virtual_server the only possible value for rc: -1, -5, 0, when -1 direct exit. 0 is normal. only -5 need continue to check. Then when rc == -5 and next need cscf is sscf, but before this, cscf will set to hc->addr_conf->default_server, otherwise if no ssl_servername, will return 0, it seems works normally. I think that may be gcc bug.

rc = ngx_http_find_virtual_server(r->connection,
                                  hc->addr_conf->virtual_names,
                                  host, r, &cscf);

if (rc == -1) {
    ngx_http_close_request(r, 500);
    return -1;
}



if (hc->ssl_servername) {
    ngx_http_ssl_srv_conf_t *sscf;

    if (rc == -5) {
        cscf = hc->addr_conf->default_server;
        rc = 0;
    }

    sscf = (cscf->ctx)->srv_conf[ngx_http_ssl_module.ctx_index];

    if (sscf->verify) {
        if ((r->connection->log)->log_level >= 7) ngx_log_error_core(7, r->connection->log, 0, "client attempted to request the server name " "different from that one was negotiated")

                                                               ;
        ngx_http_finalize_request(r, 400);
        return -1;
    }
}



if (rc == -5) {
    return 0;
}

@yaoweibin
Copy link
Member

OK, I saw the code path below, it should be OK. It seems a negative warning. Should I close this issue. It should be the compile's problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants