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


test/handshake_helper.c:135:1: start of procedure early_select_server_ctx()
133.   }
134.   
135. > static int early_select_server_ctx(SSL *s, void *arg, int ignore)
136.   {
137.       const char *servername;

test/handshake_helper.c:140:5: 
138.       const unsigned char *p;
139.       size_t len, remaining;
140. >     HANDSHAKE_EX_DATA *ex_data =
141.           (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
142.   

ssl/ssl_lib.c:3784:1: start of procedure SSL_get_ex_data()
  3782.   }
  3783.   
  3784. > void *SSL_get_ex_data(const SSL *s, int idx)
  3785.   {
  3786.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3786:5: 
  3784.   void *SSL_get_ex_data(const SSL *s, int idx)
  3785.   {
  3786. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3787.   }
  3788.   

crypto/ex_data.c:379:1: start of procedure CRYPTO_get_ex_data()
    377.    * particular index in the class used by this variable
    378.    */
    379. > void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    380.   {
    381.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))

crypto/ex_data.c:381:9: Taking true branch
    379.   void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    380.   {
    381.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
                   ^
    382.           return NULL;
    383.       return sk_void_value(ad->sk, idx);

crypto/ex_data.c:382:9: 
    380.   {
    381.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
    382. >         return NULL;
    383.       return sk_void_value(ad->sk, idx);
    384.   }

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

ssl/ssl_lib.c:3787:1: return from a call to SSL_get_ex_data
  3785.   {
  3786.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3787. > }
  3788.   
  3789.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

test/handshake_helper.c:147:10: Taking false branch
145.        * was written, so parsing the normal case is a bit complex.
146.        */
147.       if (!SSL_early_get0_ext(s, TLSEXT_TYPE_server_name, &p, &remaining) ||
                ^
148.           remaining <= 2)
149.           return 0;

test/handshake_helper.c:148:9: Taking false branch
146.        */
147.       if (!SSL_early_get0_ext(s, TLSEXT_TYPE_server_name, &p, &remaining) ||
148.           remaining <= 2)
               ^
149.           return 0;
150.       /* Extract the length of the supplied list of names. */

test/handshake_helper.c:151:5: 
149.           return 0;
150.       /* Extract the length of the supplied list of names. */
151. >     len = (*(p++) << 1);
152.       len += *(p++);
153.       if (len + 2 != remaining)

test/handshake_helper.c:152:5: 
150.       /* Extract the length of the supplied list of names. */
151.       len = (*(p++) << 1);
152. >     len += *(p++);
153.       if (len + 2 != remaining)
154.           return 0;

test/handshake_helper.c:153:9: Taking false branch
151.       len = (*(p++) << 1);
152.       len += *(p++);
153.       if (len + 2 != remaining)
               ^
154.           return 0;
155.       remaining = len;

test/handshake_helper.c:155:5: 
153.       if (len + 2 != remaining)
154.           return 0;
155. >     remaining = len;
156.       /*
157.        * The list in practice only has a single element, so we only consider

test/handshake_helper.c:160:9: Taking false branch
158.        * the first one.
159.        */
160.       if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)
               ^
161.           return 0;
162.       remaining--;

test/handshake_helper.c:160:27: Taking false branch
158.        * the first one.
159.        */
160.       if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)
                                 ^
161.           return 0;
162.       remaining--;

test/handshake_helper.c:162:5: 
160.       if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)
161.           return 0;
162. >     remaining--;
163.       /* Now we can finally pull out the byte array with the actual hostname. */
164.       if (remaining <= 2)

test/handshake_helper.c:164:9: Taking false branch
162.       remaining--;
163.       /* Now we can finally pull out the byte array with the actual hostname. */
164.       if (remaining <= 2)
               ^
165.           return 0;
166.       len = (*(p++) << 1);

test/handshake_helper.c:166:5: 
164.       if (remaining <= 2)
165.           return 0;
166. >     len = (*(p++) << 1);
167.       len += *(p++);
168.       if (len + 2 > remaining)

test/handshake_helper.c:167:5: 
165.           return 0;
166.       len = (*(p++) << 1);
167. >     len += *(p++);
168.       if (len + 2 > remaining)
169.           return 0;

test/handshake_helper.c:168:9: Taking false branch
166.       len = (*(p++) << 1);
167.       len += *(p++);
168.       if (len + 2 > remaining)
               ^
169.           return 0;
170.       remaining = len;

test/handshake_helper.c:170:5: 
168.       if (len + 2 > remaining)
169.           return 0;
170. >     remaining = len;
171.       servername = (const char *)p;
172.   

test/handshake_helper.c:171:5: 
169.           return 0;
170.       remaining = len;
171. >     servername = (const char *)p;
172.   
173.       if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {

test/handshake_helper.c:173:9: Taking true branch
171.       servername = (const char *)p;
172.   
173.       if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {
               ^
174.           SSL_CTX *new_ctx = arg;
175.           SSL_set_SSL_CTX(s, new_ctx);

test/handshake_helper.c:173:37: Taking false branch
171.       servername = (const char *)p;
172.   
173.       if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {
                                           ^
174.           SSL_CTX *new_ctx = arg;
175.           SSL_set_SSL_CTX(s, new_ctx);

test/handshake_helper.c:186:16: Taking true branch
184.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
185.           return 1;
186.       } else if (len == strlen("server1") &&
                      ^
187.                  strncmp(servername, "server1", len) == 0) {
188.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;

test/handshake_helper.c:187:16: Taking true branch
185.           return 1;
186.       } else if (len == strlen("server1") &&
187.                  strncmp(servername, "server1", len) == 0) {
                      ^
188.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
189.           return 1;

test/handshake_helper.c:188:9: 
186.       } else if (len == strlen("server1") &&
187.                  strncmp(servername, "server1", len) == 0) {
188. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
189.           return 1;
190.       } else if (ignore) {

static int early_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_early_get0_ext(s, TLSEXT_TYPE_server_name, &p, &remaining) ||
        remaining <= 2)
        return 0;
    len = (*(p++) << 1);
    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++) << 1);
    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 early_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_early_get0_ext(s, TLSEXT_TYPE_server_name, &p, &remaining) ||\n        remaining <= 2)\n        return 0;\n    len = (*(p++) << 1);\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++) << 1);\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}']