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


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

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

ssl/ssl_lib.c:2366:1: start of procedure SSL_get_servername()
  2364.    */
  2365.   
  2366. > const char *SSL_get_servername(const SSL *s, const int type)
  2367.   {
  2368.       if (type != TLSEXT_NAMETYPE_host_name)

ssl/ssl_lib.c:2368:9: Taking false branch
  2366.   const char *SSL_get_servername(const SSL *s, const int type)
  2367.   {
  2368.       if (type != TLSEXT_NAMETYPE_host_name)
                  ^
  2369.           return NULL;
  2370.   

ssl/ssl_lib.c:2371:12: Condition is true
  2369.           return NULL;
  2370.   
  2371.       return s->session && !s->ext.hostname ?
                     ^
  2372.           s->session->ext.hostname : s->ext.hostname;
  2373.   }

ssl/ssl_lib.c:2371:27: Condition is true
  2369.           return NULL;
  2370.   
  2371.       return s->session && !s->ext.hostname ?
                                    ^
  2372.           s->session->ext.hostname : s->ext.hostname;
  2373.   }

ssl/ssl_lib.c:2371:12: 
  2369.           return NULL;
  2370.   
  2371. >     return s->session && !s->ext.hostname ?
  2372.           s->session->ext.hostname : s->ext.hostname;
  2373.   }

ssl/ssl_lib.c:2371:5: 
  2369.           return NULL;
  2370.   
  2371. >     return s->session && !s->ext.hostname ?
  2372.           s->session->ext.hostname : s->ext.hostname;
  2373.   }

ssl/ssl_lib.c:2373:1: return from a call to SSL_get_servername
  2371.       return s->session && !s->ext.hostname ?
  2372.           s->session->ext.hostname : s->ext.hostname;
  2373. > }
  2374.   
  2375.   int SSL_get_servername_type(const SSL *s)

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

ssl/ssl_lib.c:3729:1: start of procedure SSL_get_ex_data()
  3727.   }
  3728.   
  3729. > void *SSL_get_ex_data(const SSL *s, int idx)
  3730.   {
  3731.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3731:5: 
  3729.   void *SSL_get_ex_data(const SSL *s, int idx)
  3730.   {
  3731. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3732.   }
  3733.   

crypto/ex_data.c:387:1: start of procedure CRYPTO_get_ex_data()
    385.    * particular index in the class used by this variable
    386.    */
    387. > void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    388.   {
    389.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))

crypto/ex_data.c:389:9: Taking true branch
    387.   void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    388.   {
    389.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
                   ^
    390.           return NULL;
    391.       return sk_void_value(ad->sk, idx);

crypto/ex_data.c:390:9: 
    388.   {
    389.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
    390. >         return NULL;
    391.       return sk_void_value(ad->sk, idx);
    392.   }

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

ssl/ssl_lib.c:3732:1: return from a call to SSL_get_ex_data
  3730.   {
  3731.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3732. > }
  3733.   
  3734.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

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

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

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

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

ssl/ssl_lib.c:3585:1: start of procedure SSL_set_SSL_CTX()
  3583.   }
  3584.   
  3585. > SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)
  3586.   {
  3587.       CERT *new_cert;

ssl/ssl_lib.c:3588:9: Taking false branch
  3586.   {
  3587.       CERT *new_cert;
  3588.       if (ssl->ctx == ctx)
                  ^
  3589.           return ssl->ctx;
  3590.       if (ctx == NULL)

ssl/ssl_lib.c:3590:9: Taking false branch
  3588.       if (ssl->ctx == ctx)
  3589.           return ssl->ctx;
  3590.       if (ctx == NULL)
                  ^
  3591.           ctx = ssl->session_ctx;
  3592.       new_cert = ssl_cert_dup(ctx->cert);

ssl/ssl_lib.c:3592:5: Skipping ssl_cert_dup(): empty list of specs
  3590.       if (ctx == NULL)
  3591.           ctx = ssl->session_ctx;
  3592.       new_cert = ssl_cert_dup(ctx->cert);
              ^
  3593.       if (new_cert == NULL) {
  3594.           return NULL;

ssl/ssl_lib.c:3593:9: Taking true branch
  3591.           ctx = ssl->session_ctx;
  3592.       new_cert = ssl_cert_dup(ctx->cert);
  3593.       if (new_cert == NULL) {
                  ^
  3594.           return NULL;
  3595.       }

ssl/ssl_lib.c:3594:9: 
  3592.       new_cert = ssl_cert_dup(ctx->cert);
  3593.       if (new_cert == NULL) {
  3594. >         return NULL;
  3595.       }
  3596.       ssl_cert_free(ssl->cert);

ssl/ssl_lib.c:3623:1: return from a call to SSL_set_SSL_CTX
  3621.   
  3622.       return ssl->ctx;
  3623. > }
  3624.   
  3625.   int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)

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

ssl/ssl_lib.c:4067:1: start of procedure SSL_clear_options()
  4065.   }
  4066.   
  4067. > unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4068.   {
  4069.       return s->options &= ~op;

ssl/ssl_lib.c:4069:5: 
  4067.   unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4068.   {
  4069. >     return s->options &= ~op;
  4070.   }
  4071.   

ssl/ssl_lib.c:4070:1: return from a call to SSL_clear_options
  4068.   {
  4069.       return s->options &= ~op;
  4070. > }
  4071.   
  4072.   STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s)

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

ssl/ssl_lib.c:4042:1: start of procedure SSL_CTX_get_options()
  4040.    * control interface.
  4041.    */
  4042. > unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4043.   {
  4044.       return ctx->options;

ssl/ssl_lib.c:4044:5: 
  4042.   unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4043.   {
  4044. >     return ctx->options;
  4045.   }
  4046.   

ssl/ssl_lib.c:4045:1: return from a call to SSL_CTX_get_options
  4043.   {
  4044.       return ctx->options;
  4045. > }
  4046.   
  4047.   unsigned long SSL_get_options(const SSL *s)

ssl/ssl_lib.c:4057:1: start of procedure SSL_set_options()
  4055.   }
  4056.   
  4057. > unsigned long SSL_set_options(SSL *s, unsigned long op)
  4058.   {
  4059.       return s->options |= op;

ssl/ssl_lib.c:4059:5: 
  4057.   unsigned long SSL_set_options(SSL *s, unsigned long op)
  4058.   {
  4059. >     return s->options |= op;
  4060.   }
  4061.   

ssl/ssl_lib.c:4060:1: return from a call to SSL_set_options
  4058.   {
  4059.       return s->options |= op;
  4060. > }
  4061.   
  4062.   unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op)

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