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


test/handshake_helper.c:141:1: start of procedure client_hello_select_server_ctx()
139.   }
140.   
141. > static int client_hello_select_server_ctx(SSL *s, void *arg, int ignore)
142.   {
143.       const char *servername;

test/handshake_helper.c:146:5: 
144.       const unsigned char *p;
145.       size_t len, remaining;
146. >     HANDSHAKE_EX_DATA *ex_data =
147.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
148.   

ssl/ssl_lib.c:3926:1: start of procedure SSL_get_ex_data()
  3924.   }
  3925.   
  3926. > void *SSL_get_ex_data(const SSL *s, int idx)
  3927.   {
  3928.       return CRYPTO_get_ex_data(&s->ex_data, idx);

ssl/ssl_lib.c:3928:5: 
  3926.   void *SSL_get_ex_data(const SSL *s, int idx)
  3927.   {
  3928. >     return CRYPTO_get_ex_data(&s->ex_data, idx);
  3929.   }
  3930.   

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:3929:1: return from a call to SSL_get_ex_data
  3927.   {
  3928.       return CRYPTO_get_ex_data(&s->ex_data, idx);
  3929. > }
  3930.   
  3931.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

test/handshake_helper.c:153:10: Taking false branch
151.        * was written, so parsing the normal case is a bit complex.
152.        */
153.       if (!SSL_client_hello_get0_ext(s, TLSEXT_TYPE_server_name, &p,
                ^
154.                                      &remaining) ||
155.           remaining <= 2)

test/handshake_helper.c:155:9: Taking false branch
153.       if (!SSL_client_hello_get0_ext(s, TLSEXT_TYPE_server_name, &p,
154.                                      &remaining) ||
155.           remaining <= 2)
               ^
156.           return 0;
157.       /* Extract the length of the supplied list of names. */

test/handshake_helper.c:158:5: 
156.           return 0;
157.       /* Extract the length of the supplied list of names. */
158. >     len = (*(p++) << 8);
159.       len += *(p++);
160.       if (len + 2 != remaining)

test/handshake_helper.c:159:5: 
157.       /* Extract the length of the supplied list of names. */
158.       len = (*(p++) << 8);
159. >     len += *(p++);
160.       if (len + 2 != remaining)
161.           return 0;

test/handshake_helper.c:160:9: Taking false branch
158.       len = (*(p++) << 8);
159.       len += *(p++);
160.       if (len + 2 != remaining)
               ^
161.           return 0;
162.       remaining = len;

test/handshake_helper.c:162:5: 
160.       if (len + 2 != remaining)
161.           return 0;
162. >     remaining = len;
163.       /*
164.        * The list in practice only has a single element, so we only consider

test/handshake_helper.c:167:9: Taking false branch
165.        * the first one.
166.        */
167.       if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)
               ^
168.           return 0;
169.       remaining--;

test/handshake_helper.c:167:27: Taking false branch
165.        * the first one.
166.        */
167.       if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)
                                 ^
168.           return 0;
169.       remaining--;

test/handshake_helper.c:169:5: 
167.       if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)
168.           return 0;
169. >     remaining--;
170.       /* Now we can finally pull out the byte array with the actual hostname. */
171.       if (remaining <= 2)

test/handshake_helper.c:171:9: Taking false branch
169.       remaining--;
170.       /* Now we can finally pull out the byte array with the actual hostname. */
171.       if (remaining <= 2)
               ^
172.           return 0;
173.       len = (*(p++) << 8);

test/handshake_helper.c:173:5: 
171.       if (remaining <= 2)
172.           return 0;
173. >     len = (*(p++) << 8);
174.       len += *(p++);
175.       if (len + 2 > remaining)

test/handshake_helper.c:174:5: 
172.           return 0;
173.       len = (*(p++) << 8);
174. >     len += *(p++);
175.       if (len + 2 > remaining)
176.           return 0;

test/handshake_helper.c:175:9: Taking false branch
173.       len = (*(p++) << 8);
174.       len += *(p++);
175.       if (len + 2 > remaining)
               ^
176.           return 0;
177.       remaining = len;

test/handshake_helper.c:177:5: 
175.       if (len + 2 > remaining)
176.           return 0;
177. >     remaining = len;
178.       servername = (const char *)p;
179.   

test/handshake_helper.c:178:5: 
176.           return 0;
177.       remaining = len;
178. >     servername = (const char *)p;
179.   
180.       if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {

test/handshake_helper.c:180:9: Taking false branch
178.       servername = (const char *)p;
179.   
180.       if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {
               ^
181.           SSL_CTX *new_ctx = arg;
182.           SSL_set_SSL_CTX(s, new_ctx);

test/handshake_helper.c:193:16: Taking true branch
191.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
192.           return 1;
193.       } else if (len == strlen("server1") &&
                      ^
194.                  strncmp(servername, "server1", len) == 0) {
195.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;

test/handshake_helper.c:194:16: Taking true branch
192.           return 1;
193.       } else if (len == strlen("server1") &&
194.                  strncmp(servername, "server1", len) == 0) {
                      ^
195.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
196.           return 1;

test/handshake_helper.c:195:9: 
193.       } else if (len == strlen("server1") &&
194.                  strncmp(servername, "server1", len) == 0) {
195. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
196.           return 1;
197.       } else if (ignore) {

static int client_hello_select_server_ctx(SSL *s, void *arg, int ignore)
{
    const char *servername;
    const unsigned char *p;
    size_t len, remaining;
    HANDSHAKE_EX_DATA *ex_data =
        (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
    if (!SSL_client_hello_get0_ext(s, TLSEXT_TYPE_server_name, &p,
                                   &remaining) ||
        remaining <= 2)
        return 0;
    len = (*(p++) << 8);
    len += *(p++);
    if (len + 2 != remaining)
        return 0;
    remaining = len;
    if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)
        return 0;
    remaining--;
    if (remaining <= 2)
        return 0;
    len = (*(p++) << 8);
    len += *(p++);
    if (len + 2 > remaining)
        return 0;
    remaining = len;
    servername = (const char *)p;
    if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {
        SSL_CTX *new_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 1;
    } else if (len == strlen("server1") &&
               strncmp(servername, "server1", len) == 0) {
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
        return 1;
    } else if (ignore) {
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
        return 1;
    }
    return 0;
}
['static int client_hello_select_server_ctx(SSL *s, void *arg, int ignore)\n{\n    const char *servername;\n    const unsigned char *p;\n    size_t len, remaining;\n    HANDSHAKE_EX_DATA *ex_data =\n        (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n    if (!SSL_client_hello_get0_ext(s, TLSEXT_TYPE_server_name, &p,\n                                   &remaining) ||\n        remaining <= 2)\n        return 0;\n    len = (*(p++) << 8);\n    len += *(p++);\n    if (len + 2 != remaining)\n        return 0;\n    remaining = len;\n    if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)\n        return 0;\n    remaining--;\n    if (remaining <= 2)\n        return 0;\n    len = (*(p++) << 8);\n    len += *(p++);\n    if (len + 2 > remaining)\n        return 0;\n    remaining = len;\n    servername = (const char *)p;\n    if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {\n        SSL_CTX *new_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 1;\n    } else if (len == strlen("server1") &&\n               strncmp(servername, "server1", len) == 0) {\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n        return 1;\n    } else if (ignore) {\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n        return 1;\n    }\n    return 0;\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}']