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


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

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

ssl/ssl_lib.c:3745:1: start of procedure SSL_get_ex_data()
  3743.   }
  3744.   
  3745. > void *SSL_get_ex_data(const SSL *s, int idx)
  3746.   {
  3747.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3747:5: 
  3745.   void *SSL_get_ex_data(const SSL *s, int idx)
  3746.   {
  3747. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3748.   }
  3749.   

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:3748:1: return from a call to SSL_get_ex_data
  3746.   {
  3747.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3748. > }
  3749.   
  3750.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test/handshake_helper.c:198:16: Taking true branch
196.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
197.           return 1;
198.       } else if (ignore) {
                      ^
199.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
200.           return 1;

test/handshake_helper.c:199:9: 
197.           return 1;
198.       } else if (ignore) {
199. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
200.           return 1;
201.       }

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