test/handshake_helper.c:112: error: NULL_DEREFERENCE
  pointer `ex_data` last assigned on line 93 could be null and is dereferenced at line 112, column 9.
Showing all 40 steps of the trace


test/handshake_helper.c:90:1: start of procedure select_server_ctx()
88.    * An empty SNI extension also returns SSL_TSLEXT_ERR_NOACK.
89.    */
90. > static int select_server_ctx(SSL *s, void *arg, int ignore)
91.   {
92.       const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);

test/handshake_helper.c:92:5: 
90.   static int select_server_ctx(SSL *s, void *arg, int ignore)
91.   {
92. >     const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
93.       HANDSHAKE_EX_DATA *ex_data =
94.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));

ssl/ssl_lib.c:2163:1: start of procedure SSL_get_servername()
  2161.    */
  2162.   
  2163. > const char *SSL_get_servername(const SSL *s, const int type)
  2164.   {
  2165.       if (type != TLSEXT_NAMETYPE_host_name)

ssl/ssl_lib.c:2165:9: Taking false branch
  2163.   const char *SSL_get_servername(const SSL *s, const int type)
  2164.   {
  2165.       if (type != TLSEXT_NAMETYPE_host_name)
                  ^
  2166.           return NULL;
  2167.   

ssl/ssl_lib.c:2168:12: Condition is true
  2166.           return NULL;
  2167.   
  2168.       return s->session && !s->ext.hostname ?
                     ^
  2169.           s->session->ext.hostname : s->ext.hostname;
  2170.   }

ssl/ssl_lib.c:2168:27: Condition is true
  2166.           return NULL;
  2167.   
  2168.       return s->session && !s->ext.hostname ?
                                    ^
  2169.           s->session->ext.hostname : s->ext.hostname;
  2170.   }

ssl/ssl_lib.c:2168:12: 
  2166.           return NULL;
  2167.   
  2168. >     return s->session && !s->ext.hostname ?
  2169.           s->session->ext.hostname : s->ext.hostname;
  2170.   }

ssl/ssl_lib.c:2168:5: 
  2166.           return NULL;
  2167.   
  2168. >     return s->session && !s->ext.hostname ?
  2169.           s->session->ext.hostname : s->ext.hostname;
  2170.   }

ssl/ssl_lib.c:2170:1: return from a call to SSL_get_servername
  2168.       return s->session && !s->ext.hostname ?
  2169.           s->session->ext.hostname : s->ext.hostname;
  2170. > }
  2171.   
  2172.   int SSL_get_servername_type(const SSL *s)

test/handshake_helper.c:93:5: 
91.   {
92.       const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
93. >     HANDSHAKE_EX_DATA *ex_data =
94.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
95.   

ssl/ssl_lib.c:3604:1: start of procedure SSL_get_ex_data()
  3602.   }
  3603.   
  3604. > void *SSL_get_ex_data(const SSL *s, int idx)
  3605.   {
  3606.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3606:5: 
  3604.   void *SSL_get_ex_data(const SSL *s, int idx)
  3605.   {
  3606. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3607.   }
  3608.   

crypto/ex_data.c:375:1: start of procedure CRYPTO_get_ex_data()
    373.    * particular index in the class used by this variable
    374.    */
    375. > void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    376.   {
    377.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))

crypto/ex_data.c:377:9: Taking true branch
    375.   void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    376.   {
    377.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
                   ^
    378.           return NULL;
    379.       return sk_void_value(ad->sk, idx);

crypto/ex_data.c:378:9: 
    376.   {
    377.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
    378. >         return NULL;
    379.       return sk_void_value(ad->sk, idx);
    380.   }

crypto/ex_data.c:380:1: return from a call to CRYPTO_get_ex_data
    378.           return NULL;
    379.       return sk_void_value(ad->sk, idx);
    380. > }

ssl/ssl_lib.c:3607:1: return from a call to SSL_get_ex_data
  3605.   {
  3606.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3607. > }
  3608.   
  3609.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

test/handshake_helper.c:96:9: Taking false branch
94.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
95.   
96.       if (servername == NULL) {
              ^
97.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
98.           return SSL_TLSEXT_ERR_NOACK;

test/handshake_helper.c:101:9: Taking true branch
99.       }
100.   
101.       if (strcmp(servername, "server2") == 0) {
               ^
102.           SSL_CTX *new_ctx = (SSL_CTX*)arg;
103.           SSL_set_SSL_CTX(s, new_ctx);

test/handshake_helper.c:102:9: 
100.   
101.       if (strcmp(servername, "server2") == 0) {
102. >         SSL_CTX *new_ctx = (SSL_CTX*)arg;
103.           SSL_set_SSL_CTX(s, new_ctx);
104.           /*

test/handshake_helper.c:103:9: 
101.       if (strcmp(servername, "server2") == 0) {
102.           SSL_CTX *new_ctx = (SSL_CTX*)arg;
103. >         SSL_set_SSL_CTX(s, new_ctx);
104.           /*
105.            * Copy over all the SSL_CTX options - reasonable behavior

ssl/ssl_lib.c:3460:1: start of procedure SSL_set_SSL_CTX()
  3458.   }
  3459.   
  3460. > SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)
  3461.   {
  3462.       CERT *new_cert;

ssl/ssl_lib.c:3463:9: Taking false branch
  3461.   {
  3462.       CERT *new_cert;
  3463.       if (ssl->ctx == ctx)
                  ^
  3464.           return ssl->ctx;
  3465.       if (ctx == NULL)

ssl/ssl_lib.c:3465:9: Taking false branch
  3463.       if (ssl->ctx == ctx)
  3464.           return ssl->ctx;
  3465.       if (ctx == NULL)
                  ^
  3466.           ctx = ssl->initial_ctx;
  3467.       new_cert = ssl_cert_dup(ctx->cert);

ssl/ssl_lib.c:3467:5: Skipping ssl_cert_dup(): empty list of specs
  3465.       if (ctx == NULL)
  3466.           ctx = ssl->initial_ctx;
  3467.       new_cert = ssl_cert_dup(ctx->cert);
              ^
  3468.       if (new_cert == NULL) {
  3469.           return NULL;

ssl/ssl_lib.c:3468:9: Taking true branch
  3466.           ctx = ssl->initial_ctx;
  3467.       new_cert = ssl_cert_dup(ctx->cert);
  3468.       if (new_cert == NULL) {
                  ^
  3469.           return NULL;
  3470.       }

ssl/ssl_lib.c:3469:9: 
  3467.       new_cert = ssl_cert_dup(ctx->cert);
  3468.       if (new_cert == NULL) {
  3469. >         return NULL;
  3470.       }
  3471.       ssl_cert_free(ssl->cert);

ssl/ssl_lib.c:3498:1: return from a call to SSL_set_SSL_CTX
  3496.   
  3497.       return ssl->ctx;
  3498. > }
  3499.   
  3500.   int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)

test/handshake_helper.c:109:9: 
107.            * contexts differ/conflict
108.            */
109. >         SSL_clear_options(s, 0xFFFFFFFFL);
110.           SSL_set_options(s, SSL_CTX_get_options(new_ctx));
111.   

ssl/ssl_lib.c:3947:1: start of procedure SSL_clear_options()
  3945.   }
  3946.   
  3947. > unsigned long SSL_clear_options(SSL *s, unsigned long op)
  3948.   {
  3949.       return s->options &= ~op;

ssl/ssl_lib.c:3949:5: 
  3947.   unsigned long SSL_clear_options(SSL *s, unsigned long op)
  3948.   {
  3949. >     return s->options &= ~op;
  3950.   }
  3951.   

ssl/ssl_lib.c:3950:1: return from a call to SSL_clear_options
  3948.   {
  3949.       return s->options &= ~op;
  3950. > }
  3951.   
  3952.   STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s)

test/handshake_helper.c:110:9: 
108.            */
109.           SSL_clear_options(s, 0xFFFFFFFFL);
110. >         SSL_set_options(s, SSL_CTX_get_options(new_ctx));
111.   
112.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;

ssl/ssl_lib.c:3922:1: start of procedure SSL_CTX_get_options()
  3920.    * control interface.
  3921.    */
  3922. > unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  3923.   {
  3924.       return ctx->options;

ssl/ssl_lib.c:3924:5: 
  3922.   unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  3923.   {
  3924. >     return ctx->options;
  3925.   }
  3926.   

ssl/ssl_lib.c:3925:1: return from a call to SSL_CTX_get_options
  3923.   {
  3924.       return ctx->options;
  3925. > }
  3926.   
  3927.   unsigned long SSL_get_options(const SSL *s)

ssl/ssl_lib.c:3937:1: start of procedure SSL_set_options()
  3935.   }
  3936.   
  3937. > unsigned long SSL_set_options(SSL *s, unsigned long op)
  3938.   {
  3939.       return s->options |= op;

ssl/ssl_lib.c:3939:5: 
  3937.   unsigned long SSL_set_options(SSL *s, unsigned long op)
  3938.   {
  3939. >     return s->options |= op;
  3940.   }
  3941.   

ssl/ssl_lib.c:3940:1: return from a call to SSL_set_options
  3938.   {
  3939.       return s->options |= op;
  3940. > }
  3941.   
  3942.   unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op)

test/handshake_helper.c:112:9: 
110.           SSL_set_options(s, SSL_CTX_get_options(new_ctx));
111.   
112. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
113.           return SSL_TLSEXT_ERR_OK;
114.       } else if (strcmp(servername, "server1") == 0) {

static int select_server_ctx(SSL *s, void *arg, int ignore)
{
    const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
    HANDSHAKE_EX_DATA *ex_data =
        (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
    if (servername == NULL) {
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
        return SSL_TLSEXT_ERR_NOACK;
    }
    if (strcmp(servername, "server2") == 0) {
        SSL_CTX *new_ctx = (SSL_CTX*)arg;
        SSL_set_SSL_CTX(s, new_ctx);
        SSL_clear_options(s, 0xFFFFFFFFL);
        SSL_set_options(s, SSL_CTX_get_options(new_ctx));
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
        return SSL_TLSEXT_ERR_OK;
    } else if (strcmp(servername, "server1") == 0) {
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
        return SSL_TLSEXT_ERR_OK;
    } else if (ignore) {
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
        return SSL_TLSEXT_ERR_NOACK;
    } else {
        return SSL_TLSEXT_ERR_ALERT_FATAL;
    }
}
['static int select_server_ctx(SSL *s, void *arg, int ignore)\n{\n    const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);\n    HANDSHAKE_EX_DATA *ex_data =\n        (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n    if (servername == NULL) {\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n        return SSL_TLSEXT_ERR_NOACK;\n    }\n    if (strcmp(servername, "server2") == 0) {\n        SSL_CTX *new_ctx = (SSL_CTX*)arg;\n        SSL_set_SSL_CTX(s, new_ctx);\n        SSL_clear_options(s, 0xFFFFFFFFL);\n        SSL_set_options(s, SSL_CTX_get_options(new_ctx));\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;\n        return SSL_TLSEXT_ERR_OK;\n    } else if (strcmp(servername, "server1") == 0) {\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n        return SSL_TLSEXT_ERR_OK;\n    } else if (ignore) {\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n        return SSL_TLSEXT_ERR_NOACK;\n    } else {\n        return SSL_TLSEXT_ERR_ALERT_FATAL;\n    }\n}', 'const char *SSL_get_servername(const SSL *s, const int type)\n{\n    if (type != TLSEXT_NAMETYPE_host_name)\n        return NULL;\n    return s->session && !s->ext.hostname ?\n        s->session->ext.hostname : s->ext.hostname;\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n    return (CRYPTO_get_ex_data(&s->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n    if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n        return NULL;\n    return sk_void_value(ad->sk, idx);\n}', 'SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)\n{\n    CERT *new_cert;\n    if (ssl->ctx == ctx)\n        return ssl->ctx;\n    if (ctx == NULL)\n        ctx = ssl->initial_ctx;\n    new_cert = ssl_cert_dup(ctx->cert);\n    if (new_cert == NULL) {\n        return NULL;\n    }\n    ssl_cert_free(ssl->cert);\n    ssl->cert = new_cert;\n    OPENSSL_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx));\n    if ((ssl->ctx != NULL) &&\n        (ssl->sid_ctx_length == ssl->ctx->sid_ctx_length) &&\n        (memcmp(ssl->sid_ctx, ssl->ctx->sid_ctx, ssl->sid_ctx_length) == 0)) {\n        ssl->sid_ctx_length = ctx->sid_ctx_length;\n        memcpy(&ssl->sid_ctx, &ctx->sid_ctx, sizeof(ssl->sid_ctx));\n    }\n    SSL_CTX_up_ref(ctx);\n    SSL_CTX_free(ssl->ctx);\n    ssl->ctx = ctx;\n    return ssl->ctx;\n}', 'unsigned long SSL_clear_options(SSL *s, unsigned long op)\n{\n    return s->options &= ~op;\n}', 'unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)\n{\n    return ctx->options;\n}', 'unsigned long SSL_set_options(SSL *s, unsigned long op)\n{\n    return s->options |= op;\n}']