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


test/handshake_helper.c:110:1: start of procedure select_server_ctx()
108.    * An empty SNI extension also returns SSL_TSLEXT_ERR_NOACK.
109.    */
110. > static int select_server_ctx(SSL *s, void *arg, int ignore)
111.   {
112.       const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);

test/handshake_helper.c:112:5: 
110.   static int select_server_ctx(SSL *s, void *arg, int ignore)
111.   {
112. >     const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
113.       HANDSHAKE_EX_DATA *ex_data =
114.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));

ssl/ssl_lib.c:2598:1: start of procedure SSL_get_servername()
  2596.    */
  2597.   
  2598. > const char *SSL_get_servername(const SSL *s, const int type)
  2599.   {
  2600.       if (type != TLSEXT_NAMETYPE_host_name)

ssl/ssl_lib.c:2600:9: Taking false branch
  2598.   const char *SSL_get_servername(const SSL *s, const int type)
  2599.   {
  2600.       if (type != TLSEXT_NAMETYPE_host_name)
                  ^
  2601.           return NULL;
  2602.   

ssl/ssl_lib.c:2603:12: Condition is true
  2601.           return NULL;
  2602.   
  2603.       return s->session && !s->ext.hostname ?
                     ^
  2604.           s->session->ext.hostname : s->ext.hostname;
  2605.   }

ssl/ssl_lib.c:2603:27: Condition is true
  2601.           return NULL;
  2602.   
  2603.       return s->session && !s->ext.hostname ?
                                    ^
  2604.           s->session->ext.hostname : s->ext.hostname;
  2605.   }

ssl/ssl_lib.c:2603:12: 
  2601.           return NULL;
  2602.   
  2603. >     return s->session && !s->ext.hostname ?
  2604.           s->session->ext.hostname : s->ext.hostname;
  2605.   }

ssl/ssl_lib.c:2603:5: 
  2601.           return NULL;
  2602.   
  2603. >     return s->session && !s->ext.hostname ?
  2604.           s->session->ext.hostname : s->ext.hostname;
  2605.   }

ssl/ssl_lib.c:2605:1: return from a call to SSL_get_servername
  2603.       return s->session && !s->ext.hostname ?
  2604.           s->session->ext.hostname : s->ext.hostname;
  2605. > }
  2606.   
  2607.   int SSL_get_servername_type(const SSL *s)

test/handshake_helper.c:113:5: 
111.   {
112.       const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
113. >     HANDSHAKE_EX_DATA *ex_data =
114.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
115.   

ssl/ssl_lib.c:4045:1: start of procedure SSL_get_ex_data()
  4043.   }
  4044.   
  4045. > void *SSL_get_ex_data(const SSL *s, int idx)
  4046.   {
  4047.       return CRYPTO_get_ex_data(&s->ex_data, idx);

ssl/ssl_lib.c:4047:5: 
  4045.   void *SSL_get_ex_data(const SSL *s, int idx)
  4046.   {
  4047. >     return CRYPTO_get_ex_data(&s->ex_data, idx);
  4048.   }
  4049.   

crypto/ex_data.c:393:1: start of procedure CRYPTO_get_ex_data()
    391.    * particular index in the class used by this variable
    392.    */
    393. > void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    394.   {
    395.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))

crypto/ex_data.c:395:9: Taking true branch
    393.   void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    394.   {
    395.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
                   ^
    396.           return NULL;
    397.       return sk_void_value(ad->sk, idx);

crypto/ex_data.c:396:9: 
    394.   {
    395.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
    396. >         return NULL;
    397.       return sk_void_value(ad->sk, idx);
    398.   }

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

ssl/ssl_lib.c:4048:1: return from a call to SSL_get_ex_data
  4046.   {
  4047.       return CRYPTO_get_ex_data(&s->ex_data, idx);
  4048. > }
  4049.   
  4050.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

test/handshake_helper.c:116:9: Taking false branch
114.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
115.   
116.       if (servername == NULL) {
               ^
117.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
118.           return SSL_TLSEXT_ERR_NOACK;

test/handshake_helper.c:121:9: Taking true branch
119.       }
120.   
121.       if (strcmp(servername, "server2") == 0) {
               ^
122.           SSL_CTX *new_ctx = (SSL_CTX*)arg;
123.           SSL_set_SSL_CTX(s, new_ctx);

test/handshake_helper.c:122:9: 
120.   
121.       if (strcmp(servername, "server2") == 0) {
122. >         SSL_CTX *new_ctx = (SSL_CTX*)arg;
123.           SSL_set_SSL_CTX(s, new_ctx);
124.           /*

test/handshake_helper.c:123:9: 
121.       if (strcmp(servername, "server2") == 0) {
122.           SSL_CTX *new_ctx = (SSL_CTX*)arg;
123. >         SSL_set_SSL_CTX(s, new_ctx);
124.           /*
125.            * Copy over all the SSL_CTX options - reasonable behavior

ssl/ssl_lib.c:3882:1: start of procedure SSL_set_SSL_CTX()
  3880.   }
  3881.   
  3882. > SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)
  3883.   {
  3884.       CERT *new_cert;

ssl/ssl_lib.c:3885:9: Taking false branch
  3883.   {
  3884.       CERT *new_cert;
  3885.       if (ssl->ctx == ctx)
                  ^
  3886.           return ssl->ctx;
  3887.       if (ctx == NULL)

ssl/ssl_lib.c:3887:9: Taking false branch
  3885.       if (ssl->ctx == ctx)
  3886.           return ssl->ctx;
  3887.       if (ctx == NULL)
                  ^
  3888.           ctx = ssl->session_ctx;
  3889.       new_cert = ssl_cert_dup(ctx->cert);

ssl/ssl_lib.c:3889:5: Skipping ssl_cert_dup(): empty list of specs
  3887.       if (ctx == NULL)
  3888.           ctx = ssl->session_ctx;
  3889.       new_cert = ssl_cert_dup(ctx->cert);
              ^
  3890.       if (new_cert == NULL) {
  3891.           return NULL;

ssl/ssl_lib.c:3890:9: Taking false branch
  3888.           ctx = ssl->session_ctx;
  3889.       new_cert = ssl_cert_dup(ctx->cert);
  3890.       if (new_cert == NULL) {
                  ^
  3891.           return NULL;
  3892.       }

ssl/ssl_lib.c:3894:10: Taking false branch
  3892.       }
  3893.   
  3894.       if (!custom_exts_copy_flags(&new_cert->custext, &ssl->cert->custext)) {
                   ^
  3895.           ssl_cert_free(new_cert);
  3896.           return NULL;

ssl/ssl_lib.c:3899:5: 
  3897.       }
  3898.   
  3899. >     ssl_cert_free(ssl->cert);
  3900.       ssl->cert = new_cert;
  3901.   

ssl/ssl_cert.c:224:1: start of procedure ssl_cert_free()
    222.   }
    223.   
    224. > void ssl_cert_free(CERT *c)
    225.   {
    226.       int i;

ssl/ssl_cert.c:228:9: Taking true branch
    226.       int i;
    227.   
    228.       if (c == NULL)
                   ^
    229.           return;
    230.   

ssl/ssl_cert.c:229:9: 
    227.   
    228.       if (c == NULL)
    229. >         return;
    230.   
    231.       CRYPTO_DOWN_REF(&c->references, &i, c->lock);

ssl/ssl_cert.c:254:1: return from a call to ssl_cert_free
    252.       CRYPTO_THREAD_lock_free(c->lock);
    253.       OPENSSL_free(c);
    254. > }
    255.   
    256.   int ssl_cert_set0_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain)

ssl/ssl_lib.c:3900:5: 
  3898.   
  3899.       ssl_cert_free(ssl->cert);
  3900. >     ssl->cert = new_cert;
  3901.   
  3902.       /*

ssl/ssl_lib.c:3906:10: Condition is false
  3904.        * so setter APIs must prevent invalid lengths from entering the system.
  3905.        */
  3906.       if (!ossl_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx)))
                   ^
  3907.           return NULL;
  3908.   

ssl/ssl_lib.c:3906:10: Taking true branch
  3904.        * so setter APIs must prevent invalid lengths from entering the system.
  3905.        */
  3906.       if (!ossl_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx)))
                   ^
  3907.           return NULL;
  3908.   

ssl/ssl_lib.c:3907:9: 
  3905.        */
  3906.       if (!ossl_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx)))
  3907. >         return NULL;
  3908.   
  3909.       /*

ssl/ssl_lib.c:3927:1: return from a call to SSL_set_SSL_CTX
  3925.   
  3926.       return ssl->ctx;
  3927. > }
  3928.   
  3929.   int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)

test/handshake_helper.c:129:9: 
127.            * contexts differ/conflict
128.            */
129. >         SSL_clear_options(s, 0xFFFFFFFFL);
130.           SSL_set_options(s, SSL_CTX_get_options(new_ctx));
131.   

ssl/ssl_lib.c:4469:1: start of procedure SSL_clear_options()
  4467.   }
  4468.   
  4469. > unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4470.   {
  4471.       return s->options &= ~op;

ssl/ssl_lib.c:4471:5: 
  4469.   unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4470.   {
  4471. >     return s->options &= ~op;
  4472.   }
  4473.   

ssl/ssl_lib.c:4472:1: return from a call to SSL_clear_options
  4470.   {
  4471.       return s->options &= ~op;
  4472. > }
  4473.   
  4474.   STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s)

test/handshake_helper.c:130:9: 
128.            */
129.           SSL_clear_options(s, 0xFFFFFFFFL);
130. >         SSL_set_options(s, SSL_CTX_get_options(new_ctx));
131.   
132.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;

ssl/ssl_lib.c:4444:1: start of procedure SSL_CTX_get_options()
  4442.    * control interface.
  4443.    */
  4444. > unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4445.   {
  4446.       return ctx->options;

ssl/ssl_lib.c:4446:5: 
  4444.   unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4445.   {
  4446. >     return ctx->options;
  4447.   }
  4448.   

ssl/ssl_lib.c:4447:1: return from a call to SSL_CTX_get_options
  4445.   {
  4446.       return ctx->options;
  4447. > }
  4448.   
  4449.   unsigned long SSL_get_options(const SSL *s)

ssl/ssl_lib.c:4459:1: start of procedure SSL_set_options()
  4457.   }
  4458.   
  4459. > unsigned long SSL_set_options(SSL *s, unsigned long op)
  4460.   {
  4461.       return s->options |= op;

ssl/ssl_lib.c:4461:5: 
  4459.   unsigned long SSL_set_options(SSL *s, unsigned long op)
  4460.   {
  4461. >     return s->options |= op;
  4462.   }
  4463.   

ssl/ssl_lib.c:4462:1: return from a call to SSL_set_options
  4460.   {
  4461.       return s->options |= op;
  4462. > }
  4463.   
  4464.   unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op)

test/handshake_helper.c:132:9: 
130.           SSL_set_options(s, SSL_CTX_get_options(new_ctx));
131.   
132. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
133.           return SSL_TLSEXT_ERR_OK;
134.       } 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    if (!custom_exts_copy_flags(&new_cert->custext, &ssl->cert->custext)) {\n        ssl_cert_free(new_cert);\n        return NULL;\n    }\n    ssl_cert_free(ssl->cert);\n    ssl->cert = new_cert;\n    if (!ossl_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx)))\n        return NULL;\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}', 'void ssl_cert_free(CERT *c)\n{\n    int i;\n    if (c == NULL)\n        return;\n    CRYPTO_DOWN_REF(&c->references, &i, c->lock);\n    REF_PRINT_COUNT("CERT", c);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n#ifndef OPENSSL_NO_DH\n    EVP_PKEY_free(c->dh_tmp);\n#endif\n    ssl_cert_clear_certs(c);\n    OPENSSL_free(c->conf_sigalgs);\n    OPENSSL_free(c->client_sigalgs);\n    OPENSSL_free(c->shared_sigalgs);\n    OPENSSL_free(c->ctype);\n    X509_STORE_free(c->verify_store);\n    X509_STORE_free(c->chain_store);\n    custom_exts_free(&c->custext);\n#ifndef OPENSSL_NO_PSK\n    OPENSSL_free(c->psk_identity_hint);\n#endif\n    CRYPTO_THREAD_lock_free(c->lock);\n    OPENSSL_free(c);\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}']