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


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

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

ssl/ssl_lib.c:3889:1: start of procedure SSL_get_ex_data()
  3887.   }
  3888.   
  3889. > void *SSL_get_ex_data(const SSL *s, int idx)
  3890.   {
  3891.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3891:5: 
  3889.   void *SSL_get_ex_data(const SSL *s, int idx)
  3890.   {
  3891. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3892.   }
  3893.   

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:3892:1: return from a call to SSL_get_ex_data
  3890.   {
  3891.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3892. > }
  3893.   
  3894.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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