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


test/handshake_helper.c:99:1: start of procedure select_server_ctx()
97.    * An empty SNI extension also returns SSL_TSLEXT_ERR_NOACK.
98.    */
99. > static int select_server_ctx(SSL *s, void *arg, int ignore)
100.   {
101.       const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);

test/handshake_helper.c:101:5: 
99.   static int select_server_ctx(SSL *s, void *arg, int ignore)
100.   {
101. >     const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
102.       HANDSHAKE_EX_DATA *ex_data =
103.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));

ssl/ssl_lib.c:2411:1: start of procedure SSL_get_servername()
  2409.    */
  2410.   
  2411. > const char *SSL_get_servername(const SSL *s, const int type)
  2412.   {
  2413.       if (type != TLSEXT_NAMETYPE_host_name)

ssl/ssl_lib.c:2413:9: Taking false branch
  2411.   const char *SSL_get_servername(const SSL *s, const int type)
  2412.   {
  2413.       if (type != TLSEXT_NAMETYPE_host_name)
                  ^
  2414.           return NULL;
  2415.   

ssl/ssl_lib.c:2416:12: Condition is true
  2414.           return NULL;
  2415.   
  2416.       return s->session && !s->ext.hostname ?
                     ^
  2417.           s->session->ext.hostname : s->ext.hostname;
  2418.   }

ssl/ssl_lib.c:2416:27: Condition is true
  2414.           return NULL;
  2415.   
  2416.       return s->session && !s->ext.hostname ?
                                    ^
  2417.           s->session->ext.hostname : s->ext.hostname;
  2418.   }

ssl/ssl_lib.c:2416:12: 
  2414.           return NULL;
  2415.   
  2416. >     return s->session && !s->ext.hostname ?
  2417.           s->session->ext.hostname : s->ext.hostname;
  2418.   }

ssl/ssl_lib.c:2416:5: 
  2414.           return NULL;
  2415.   
  2416. >     return s->session && !s->ext.hostname ?
  2417.           s->session->ext.hostname : s->ext.hostname;
  2418.   }

ssl/ssl_lib.c:2418:1: return from a call to SSL_get_servername
  2416.       return s->session && !s->ext.hostname ?
  2417.           s->session->ext.hostname : s->ext.hostname;
  2418. > }
  2419.   
  2420.   int SSL_get_servername_type(const SSL *s)

test/handshake_helper.c:102:5: 
100.   {
101.       const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
102. >     HANDSHAKE_EX_DATA *ex_data =
103.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
104.   

ssl/ssl_lib.c:3784:1: start of procedure SSL_get_ex_data()
  3782.   }
  3783.   
  3784. > void *SSL_get_ex_data(const SSL *s, int idx)
  3785.   {
  3786.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3786:5: 
  3784.   void *SSL_get_ex_data(const SSL *s, int idx)
  3785.   {
  3786. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3787.   }
  3788.   

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

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

crypto/ex_data.c:382:9: 
    380.   {
    381.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
    382. >         return NULL;
    383.       return sk_void_value(ad->sk, idx);
    384.   }

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

ssl/ssl_lib.c:3787:1: return from a call to SSL_get_ex_data
  3785.   {
  3786.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3787. > }
  3788.   
  3789.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

test/handshake_helper.c:105:9: Taking false branch
103.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
104.   
105.       if (servername == NULL) {
               ^
106.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
107.           return SSL_TLSEXT_ERR_NOACK;

test/handshake_helper.c:110:9: Taking true branch
108.       }
109.   
110.       if (strcmp(servername, "server2") == 0) {
               ^
111.           SSL_CTX *new_ctx = (SSL_CTX*)arg;
112.           SSL_set_SSL_CTX(s, new_ctx);

test/handshake_helper.c:111:9: 
109.   
110.       if (strcmp(servername, "server2") == 0) {
111. >         SSL_CTX *new_ctx = (SSL_CTX*)arg;
112.           SSL_set_SSL_CTX(s, new_ctx);
113.           /*

test/handshake_helper.c:112:9: 
110.       if (strcmp(servername, "server2") == 0) {
111.           SSL_CTX *new_ctx = (SSL_CTX*)arg;
112. >         SSL_set_SSL_CTX(s, new_ctx);
113.           /*
114.            * Copy over all the SSL_CTX options - reasonable behavior

ssl/ssl_lib.c:3640:1: start of procedure SSL_set_SSL_CTX()
  3638.   }
  3639.   
  3640. > SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)
  3641.   {
  3642.       CERT *new_cert;

ssl/ssl_lib.c:3643:9: Taking false branch
  3641.   {
  3642.       CERT *new_cert;
  3643.       if (ssl->ctx == ctx)
                  ^
  3644.           return ssl->ctx;
  3645.       if (ctx == NULL)

ssl/ssl_lib.c:3645:9: Taking false branch
  3643.       if (ssl->ctx == ctx)
  3644.           return ssl->ctx;
  3645.       if (ctx == NULL)
                  ^
  3646.           ctx = ssl->session_ctx;
  3647.       new_cert = ssl_cert_dup(ctx->cert);

ssl/ssl_lib.c:3647:5: Skipping ssl_cert_dup(): empty list of specs
  3645.       if (ctx == NULL)
  3646.           ctx = ssl->session_ctx;
  3647.       new_cert = ssl_cert_dup(ctx->cert);
              ^
  3648.       if (new_cert == NULL) {
  3649.           return NULL;

ssl/ssl_lib.c:3648:9: Taking true branch
  3646.           ctx = ssl->session_ctx;
  3647.       new_cert = ssl_cert_dup(ctx->cert);
  3648.       if (new_cert == NULL) {
                  ^
  3649.           return NULL;
  3650.       }

ssl/ssl_lib.c:3649:9: 
  3647.       new_cert = ssl_cert_dup(ctx->cert);
  3648.       if (new_cert == NULL) {
  3649. >         return NULL;
  3650.       }
  3651.       ssl_cert_free(ssl->cert);

ssl/ssl_lib.c:3678:1: return from a call to SSL_set_SSL_CTX
  3676.   
  3677.       return ssl->ctx;
  3678. > }
  3679.   
  3680.   int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)

test/handshake_helper.c:118:9: 
116.            * contexts differ/conflict
117.            */
118. >         SSL_clear_options(s, 0xFFFFFFFFL);
119.           SSL_set_options(s, SSL_CTX_get_options(new_ctx));
120.   

ssl/ssl_lib.c:4122:1: start of procedure SSL_clear_options()
  4120.   }
  4121.   
  4122. > unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4123.   {
  4124.       return s->options &= ~op;

ssl/ssl_lib.c:4124:5: 
  4122.   unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4123.   {
  4124. >     return s->options &= ~op;
  4125.   }
  4126.   

ssl/ssl_lib.c:4125:1: return from a call to SSL_clear_options
  4123.   {
  4124.       return s->options &= ~op;
  4125. > }
  4126.   
  4127.   STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s)

test/handshake_helper.c:119:9: 
117.            */
118.           SSL_clear_options(s, 0xFFFFFFFFL);
119. >         SSL_set_options(s, SSL_CTX_get_options(new_ctx));
120.   
121.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;

ssl/ssl_lib.c:4097:1: start of procedure SSL_CTX_get_options()
  4095.    * control interface.
  4096.    */
  4097. > unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4098.   {
  4099.       return ctx->options;

ssl/ssl_lib.c:4099:5: 
  4097.   unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4098.   {
  4099. >     return ctx->options;
  4100.   }
  4101.   

ssl/ssl_lib.c:4100:1: return from a call to SSL_CTX_get_options
  4098.   {
  4099.       return ctx->options;
  4100. > }
  4101.   
  4102.   unsigned long SSL_get_options(const SSL *s)

ssl/ssl_lib.c:4112:1: start of procedure SSL_set_options()
  4110.   }
  4111.   
  4112. > unsigned long SSL_set_options(SSL *s, unsigned long op)
  4113.   {
  4114.       return s->options |= op;

ssl/ssl_lib.c:4114:5: 
  4112.   unsigned long SSL_set_options(SSL *s, unsigned long op)
  4113.   {
  4114. >     return s->options |= op;
  4115.   }
  4116.   

ssl/ssl_lib.c:4115:1: return from a call to SSL_set_options
  4113.   {
  4114.       return s->options |= op;
  4115. > }
  4116.   
  4117.   unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op)

test/handshake_helper.c:121:9: 
119.           SSL_set_options(s, SSL_CTX_get_options(new_ctx));
120.   
121. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
122.           return SSL_TLSEXT_ERR_OK;
123.       } 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->session_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}']