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


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

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

ssl/ssl_lib.c:3730:1: start of procedure SSL_get_ex_data()
  3728.   }
  3729.   
  3730. > void *SSL_get_ex_data(const SSL *s, int idx)
  3731.   {
  3732.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3732:5: 
  3730.   void *SSL_get_ex_data(const SSL *s, int idx)
  3731.   {
  3732. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3733.   }
  3734.   

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:3733:1: return from a call to SSL_get_ex_data
  3731.   {
  3732.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3733. > }
  3734.   
  3735.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test/handshake_helper.c:191:16: Taking true branch
189.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
190.           return 1;
191.       } else if (ignore) {
                      ^
192.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
193.           return 1;

test/handshake_helper.c:192:9: 
190.           return 1;
191.       } else if (ignore) {
192. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
193.           return 1;
194.       }

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}']