test/handshake_helper.c:117: error: NULL_DEREFERENCE
  pointer `ex_data` last assigned on line 113 could be null and is dereferenced at line 117, column 9.
Showing all 24 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:2610:1: start of procedure SSL_get_servername()
  2608.    */
  2609.   
  2610. > const char *SSL_get_servername(const SSL *s, const int type)
  2611.   {
  2612.       if (type != TLSEXT_NAMETYPE_host_name)

ssl/ssl_lib.c:2612:9: Taking false branch
  2610.   const char *SSL_get_servername(const SSL *s, const int type)
  2611.   {
  2612.       if (type != TLSEXT_NAMETYPE_host_name)
                  ^
  2613.           return NULL;
  2614.   

ssl/ssl_lib.c:2621:9: 
  2619.        * a clear distinction amongst those three.
  2620.        */
  2621. >     if (SSL_in_init(s))
  2622.           return s->ext.hostname;
  2623.       return (s->session != NULL && s->ext.hostname == NULL) ?

ssl/statem/statem.c:71:1: start of procedure SSL_in_init()
    69.   }
    70.   
    71. > int SSL_in_init(const SSL *s)
    72.   {
    73.       return s->statem.in_init;

ssl/statem/statem.c:73:5: 
    71.   int SSL_in_init(const SSL *s)
    72.   {
    73. >     return s->statem.in_init;
    74.   }
    75.   

ssl/statem/statem.c:74:1: return from a call to SSL_in_init
    72.   {
    73.       return s->statem.in_init;
    74. > }
    75.   
    76.   int SSL_is_init_finished(const SSL *s)

ssl/ssl_lib.c:2621:9: Taking false branch
  2619.        * a clear distinction amongst those three.
  2620.        */
  2621.       if (SSL_in_init(s))
                  ^
  2622.           return s->ext.hostname;
  2623.       return (s->session != NULL && s->ext.hostname == NULL) ?

ssl/ssl_lib.c:2623:13: Condition is true
  2621.       if (SSL_in_init(s))
  2622.           return s->ext.hostname;
  2623.       return (s->session != NULL && s->ext.hostname == NULL) ?
                      ^
  2624.           s->session->ext.hostname : s->ext.hostname;
  2625.   }

ssl/ssl_lib.c:2623:35: Condition is true
  2621.       if (SSL_in_init(s))
  2622.           return s->ext.hostname;
  2623.       return (s->session != NULL && s->ext.hostname == NULL) ?
                                            ^
  2624.           s->session->ext.hostname : s->ext.hostname;
  2625.   }

ssl/ssl_lib.c:2623:12: 
  2621.       if (SSL_in_init(s))
  2622.           return s->ext.hostname;
  2623. >     return (s->session != NULL && s->ext.hostname == NULL) ?
  2624.           s->session->ext.hostname : s->ext.hostname;
  2625.   }

ssl/ssl_lib.c:2623:5: 
  2621.       if (SSL_in_init(s))
  2622.           return s->ext.hostname;
  2623. >     return (s->session != NULL && s->ext.hostname == NULL) ?
  2624.           s->session->ext.hostname : s->ext.hostname;
  2625.   }

ssl/ssl_lib.c:2625:1: return from a call to SSL_get_servername
  2623.       return (s->session != NULL && s->ext.hostname == NULL) ?
  2624.           s->session->ext.hostname : s->ext.hostname;
  2625. > }
  2626.   
  2627.   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:4126:1: start of procedure SSL_get_ex_data()
  4124.   }
  4125.   
  4126. > void *SSL_get_ex_data(const SSL *s, int idx)
  4127.   {
  4128.       return CRYPTO_get_ex_data(&s->ex_data, idx);

ssl/ssl_lib.c:4128:5: 
  4126.   void *SSL_get_ex_data(const SSL *s, int idx)
  4127.   {
  4128. >     return CRYPTO_get_ex_data(&s->ex_data, idx);
  4129.   }
  4130.   

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

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

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

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

ssl/ssl_lib.c:4129:1: return from a call to SSL_get_ex_data
  4127.   {
  4128.       return CRYPTO_get_ex_data(&s->ex_data, idx);
  4129. > }
  4130.   
  4131.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

test/handshake_helper.c:116:9: Taking true 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:117:9: 
115.   
116.       if (servername == NULL) {
117. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
118.           return SSL_TLSEXT_ERR_NOACK;
119.       }

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    if (SSL_in_init(s))\n        return s->ext.hostname;\n    return (s->session != NULL && s->ext.hostname == NULL) ?\n        s->session->ext.hostname : s->ext.hostname;\n}', 'int SSL_in_init(const SSL *s)\n{\n    return s->statem.in_init;\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}']