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


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

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

ssl/ssl_lib.c:2084:1: start of procedure SSL_get_servername()
  2082.    */
  2083.   
  2084. > const char *SSL_get_servername(const SSL *s, const int type)
  2085.   {
  2086.       if (type != TLSEXT_NAMETYPE_host_name)

ssl/ssl_lib.c:2086:9: Taking false branch
  2084.   const char *SSL_get_servername(const SSL *s, const int type)
  2085.   {
  2086.       if (type != TLSEXT_NAMETYPE_host_name)
                  ^
  2087.           return NULL;
  2088.   

ssl/ssl_lib.c:2089:12: Condition is true
  2087.           return NULL;
  2088.   
  2089.       return s->session && !s->tlsext_hostname ?
                     ^
  2090.           s->session->tlsext_hostname : s->tlsext_hostname;
  2091.   }

ssl/ssl_lib.c:2089:27: Condition is true
  2087.           return NULL;
  2088.   
  2089.       return s->session && !s->tlsext_hostname ?
                                    ^
  2090.           s->session->tlsext_hostname : s->tlsext_hostname;
  2091.   }

ssl/ssl_lib.c:2089:12: 
  2087.           return NULL;
  2088.   
  2089. >     return s->session && !s->tlsext_hostname ?
  2090.           s->session->tlsext_hostname : s->tlsext_hostname;
  2091.   }

ssl/ssl_lib.c:2089:5: 
  2087.           return NULL;
  2088.   
  2089. >     return s->session && !s->tlsext_hostname ?
  2090.           s->session->tlsext_hostname : s->tlsext_hostname;
  2091.   }

ssl/ssl_lib.c:2091:1: return from a call to SSL_get_servername
  2089.       return s->session && !s->tlsext_hostname ?
  2090.           s->session->tlsext_hostname : s->tlsext_hostname;
  2091. > }
  2092.   
  2093.   int SSL_get_servername_type(const SSL *s)

test/handshake_helper.c:89:5: 
87.   {
88.       const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
89. >     HANDSHAKE_EX_DATA *ex_data =
90.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
91.   

ssl/ssl_lib.c:3529:1: start of procedure SSL_get_ex_data()
  3527.   }
  3528.   
  3529. > void *SSL_get_ex_data(const SSL *s, int idx)
  3530.   {
  3531.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3531:5: 
  3529.   void *SSL_get_ex_data(const SSL *s, int idx)
  3530.   {
  3531. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3532.   }
  3533.   

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

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

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

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

ssl/ssl_lib.c:3532:1: return from a call to SSL_get_ex_data
  3530.   {
  3531.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3532. > }
  3533.   
  3534.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

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

test/handshake_helper.c:97:9: Taking false branch
95.       }
96.   
97.       if (strcmp(servername, "server2") == 0) {
               ^
98.           SSL_CTX *new_ctx = (SSL_CTX*)arg;
99.           SSL_set_SSL_CTX(s, new_ctx);

test/handshake_helper.c:110:16: Taking true branch
108.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
109.           return SSL_TLSEXT_ERR_OK;
110.       } else if (strcmp(servername, "server1") == 0) {
                      ^
111.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
112.           return SSL_TLSEXT_ERR_OK;

test/handshake_helper.c:111:9: 
109.           return SSL_TLSEXT_ERR_OK;
110.       } else if (strcmp(servername, "server1") == 0) {
111. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
112.           return SSL_TLSEXT_ERR_OK;
113.       } else if (ignore) {

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->tlsext_hostname ?\n        s->session->tlsext_hostname : s->tlsext_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}']