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


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

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

ssl/ssl_lib.c:4014:1: start of procedure SSL_get_ex_data()
  4012.   }
  4013.   
  4014. > void *SSL_get_ex_data(const SSL *s, int idx)
  4015.   {
  4016.       return CRYPTO_get_ex_data(&s->ex_data, idx);

ssl/ssl_lib.c:4016:5: 
  4014.   void *SSL_get_ex_data(const SSL *s, int idx)
  4015.   {
  4016. >     return CRYPTO_get_ex_data(&s->ex_data, idx);
  4017.   }
  4018.   

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:4017:1: return from a call to SSL_get_ex_data
  4015.   {
  4016.       return CRYPTO_get_ex_data(&s->ex_data, idx);
  4017. > }
  4018.   
  4019.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

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

test/handshake_helper.c:156:9: Taking false branch
154.       if (!SSL_client_hello_get0_ext(s, TLSEXT_TYPE_server_name, &p,
155.                                      &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++) << 8);
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++) << 8);
160. >     len += *(p++);
161.       if (len + 2 != remaining)
162.           return 0;

test/handshake_helper.c:161:9: Taking false branch
159.       len = (*(p++) << 8);
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++) << 8);

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

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

test/handshake_helper.c:176:9: Taking false branch
174.       len = (*(p++) << 8);
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.       }
