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


test/handshake_helper.c:140:1: start of procedure early_select_server_ctx()
138.   }
139.   
140. > static int early_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:3883:1: start of procedure SSL_get_ex_data()
  3881.   }
  3882.   
  3883. > void *SSL_get_ex_data(const SSL *s, int idx)
  3884.   {
  3885.       return (CRYPTO_get_ex_data(&s->ex_data, idx));

ssl/ssl_lib.c:3885:5: 
  3883.   void *SSL_get_ex_data(const SSL *s, int idx)
  3884.   {
  3885. >     return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3886.   }
  3887.   

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:3886:1: return from a call to SSL_get_ex_data
  3884.   {
  3885.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3886. > }
  3887.   
  3888.   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_early_get0_ext(s, TLSEXT_TYPE_server_name, &p, &remaining) ||
                ^
153.           remaining <= 2)
154.           return 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test/handshake_helper.c:180:9: 
178.       if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {
179.           SSL_CTX *new_ctx = arg;
180. >         SSL_set_SSL_CTX(s, new_ctx);
181.           /*
182.            * Copy over all the SSL_CTX options - reasonable behavior

ssl/ssl_lib.c:3720:1: start of procedure SSL_set_SSL_CTX()
  3718.   }
  3719.   
  3720. > SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)
  3721.   {
  3722.       CERT *new_cert;

ssl/ssl_lib.c:3723:9: Taking false branch
  3721.   {
  3722.       CERT *new_cert;
  3723.       if (ssl->ctx == ctx)
                  ^
  3724.           return ssl->ctx;
  3725.       if (ctx == NULL)

ssl/ssl_lib.c:3725:9: Taking false branch
  3723.       if (ssl->ctx == ctx)
  3724.           return ssl->ctx;
  3725.       if (ctx == NULL)
                  ^
  3726.           ctx = ssl->session_ctx;
  3727.       new_cert = ssl_cert_dup(ctx->cert);

ssl/ssl_lib.c:3727:5: Skipping ssl_cert_dup(): empty list of specs
  3725.       if (ctx == NULL)
  3726.           ctx = ssl->session_ctx;
  3727.       new_cert = ssl_cert_dup(ctx->cert);
              ^
  3728.       if (new_cert == NULL) {
  3729.           return NULL;

ssl/ssl_lib.c:3728:9: Taking false branch
  3726.           ctx = ssl->session_ctx;
  3727.       new_cert = ssl_cert_dup(ctx->cert);
  3728.       if (new_cert == NULL) {
                  ^
  3729.           return NULL;
  3730.       }

ssl/ssl_lib.c:3732:10: Taking false branch
  3730.       }
  3731.   
  3732.       if (!custom_exts_copy_flags(&new_cert->custext, &ssl->cert->custext)) {
                   ^
  3733.           ssl_cert_free(new_cert);
  3734.           return NULL;

ssl/ssl_lib.c:3737:5: 
  3735.       }
  3736.   
  3737. >     ssl_cert_free(ssl->cert);
  3738.       ssl->cert = new_cert;
  3739.   

ssl/ssl_cert.c:227:1: start of procedure ssl_cert_free()
    225.   }
    226.   
    227. > void ssl_cert_free(CERT *c)
    228.   {
    229.       int i;

ssl/ssl_cert.c:231:9: Taking true branch
    229.       int i;
    230.   
    231.       if (c == NULL)
                   ^
    232.           return;
    233.   

ssl/ssl_cert.c:232:9: 
    230.   
    231.       if (c == NULL)
    232. >         return;
    233.   
    234.       CRYPTO_DOWN_REF(&c->references, &i, c->lock);

ssl/ssl_cert.c:257:1: return from a call to ssl_cert_free
    255.       CRYPTO_THREAD_lock_free(c->lock);
    256.       OPENSSL_free(c);
    257. > }
    258.   
    259.   int ssl_cert_set0_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain)

ssl/ssl_lib.c:3738:5: 
  3736.   
  3737.       ssl_cert_free(ssl->cert);
  3738. >     ssl->cert = new_cert;
  3739.   
  3740.       /*

ssl/ssl_lib.c:3744:10: Condition is true
  3742.        * so setter APIs must prevent invalid lengths from entering the system.
  3743.        */
  3744.       if (!ossl_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx)))
                   ^
  3745.           return NULL;
  3746.   

ssl/ssl_lib.c:3744:10: Taking false branch
  3742.        * so setter APIs must prevent invalid lengths from entering the system.
  3743.        */
  3744.       if (!ossl_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx)))
                   ^
  3745.           return NULL;
  3746.   

ssl/ssl_lib.c:3753:10: Taking false branch
  3751.        * leave it unchanged.
  3752.        */
  3753.       if ((ssl->ctx != NULL) &&
                   ^
  3754.           (ssl->sid_ctx_length == ssl->ctx->sid_ctx_length) &&
  3755.           (memcmp(ssl->sid_ctx, ssl->ctx->sid_ctx, ssl->sid_ctx_length) == 0)) {

ssl/ssl_lib.c:3760:5: 
  3758.       }
  3759.   
  3760. >     SSL_CTX_up_ref(ctx);
  3761.       SSL_CTX_free(ssl->ctx);     /* decrement reference count */
  3762.       ssl->ctx = ctx;

ssl/ssl_lib.c:2883:1: start of procedure SSL_CTX_up_ref()
    2881.   }
    2882.   
    2883. > int SSL_CTX_up_ref(SSL_CTX *ctx)
    2884.   {
    2885.       int i;

ssl/ssl_lib.c:2887:9: 
    2885.       int i;
    2886.   
    2887. >     if (CRYPTO_UP_REF(&ctx->references, &i, ctx->lock) <= 0)
    2888.           return 0;
    2889.   

include/internal/refcount.h:25:1: start of procedure CRYPTO_UP_REF()
      23.   typedef _Atomic int CRYPTO_REF_COUNT;
      24.   
      25. > static ossl_inline int CRYPTO_UP_REF(_Atomic int *val, int *ret, void *lock)
      26.   {
      27.       *ret = atomic_fetch_add_explicit(val, 1, memory_order_relaxed) + 1;

include/internal/refcount.h:27:5: 
      25.   static ossl_inline int CRYPTO_UP_REF(_Atomic int *val, int *ret, void *lock)
      26.   {
      27. >     *ret = atomic_fetch_add_explicit(val, 1, memory_order_relaxed) + 1;
      28.       return 1;
      29.   }

include/internal/refcount.h:28:5: 
      26.   {
      27.       *ret = atomic_fetch_add_explicit(val, 1, memory_order_relaxed) + 1;
      28. >     return 1;
      29.   }
      30.   

include/internal/refcount.h:29:1: return from a call to CRYPTO_UP_REF
      27.       *ret = atomic_fetch_add_explicit(val, 1, memory_order_relaxed) + 1;
      28.       return 1;
      29. > }
      30.   
      31.   static ossl_inline int CRYPTO_DOWN_REF(_Atomic int *val, int *ret, void *lock)

ssl/ssl_lib.c:2887:9: Taking false branch
    2885.       int i;
    2886.   
    2887.       if (CRYPTO_UP_REF(&ctx->references, &i, ctx->lock) <= 0)
                    ^
    2888.           return 0;
    2889.   

ssl/ssl_lib.c:2892:14: Condition is false
    2890.       REF_PRINT_COUNT("SSL_CTX", ctx);
    2891.       REF_ASSERT_ISNT(i < 2);
    2892.       return ((i > 1) ? 1 : 0);
                         ^
    2893.   }
    2894.   

ssl/ssl_lib.c:2892:13: 
    2890.       REF_PRINT_COUNT("SSL_CTX", ctx);
    2891.       REF_ASSERT_ISNT(i < 2);
    2892. >     return ((i > 1) ? 1 : 0);
    2893.   }
    2894.   

ssl/ssl_lib.c:2892:5: 
    2890.       REF_PRINT_COUNT("SSL_CTX", ctx);
    2891.       REF_ASSERT_ISNT(i < 2);
    2892. >     return ((i > 1) ? 1 : 0);
    2893.   }
    2894.   

ssl/ssl_lib.c:2893:1: return from a call to SSL_CTX_up_ref
    2891.       REF_ASSERT_ISNT(i < 2);
    2892.       return ((i > 1) ? 1 : 0);
    2893. > }
    2894.   
    2895.   void SSL_CTX_free(SSL_CTX *a)

ssl/ssl_lib.c:3761:5: Skipping SSL_CTX_free(): empty list of specs
  3759.   
  3760.       SSL_CTX_up_ref(ctx);
  3761.       SSL_CTX_free(ssl->ctx);     /* decrement reference count */
              ^
  3762.       ssl->ctx = ctx;
  3763.   

ssl/ssl_lib.c:3762:5: 
  3760.       SSL_CTX_up_ref(ctx);
  3761.       SSL_CTX_free(ssl->ctx);     /* decrement reference count */
  3762. >     ssl->ctx = ctx;
  3763.   
  3764.       return ssl->ctx;

ssl/ssl_lib.c:3764:5: 
  3762.       ssl->ctx = ctx;
  3763.   
  3764. >     return ssl->ctx;
  3765.   }
  3766.   

ssl/ssl_lib.c:3765:1: return from a call to SSL_set_SSL_CTX
  3763.   
  3764.       return ssl->ctx;
  3765. > }
  3766.   
  3767.   int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)

test/handshake_helper.c:186:9: 
184.            * contexts differ/conflict
185.            */
186. >         SSL_clear_options(s, 0xFFFFFFFFL);
187.           SSL_set_options(s, SSL_CTX_get_options(new_ctx));
188.   

ssl/ssl_lib.c:4301:1: start of procedure SSL_clear_options()
  4299.   }
  4300.   
  4301. > unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4302.   {
  4303.       return s->options &= ~op;

ssl/ssl_lib.c:4303:5: 
  4301.   unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4302.   {
  4303. >     return s->options &= ~op;
  4304.   }
  4305.   

ssl/ssl_lib.c:4304:1: return from a call to SSL_clear_options
  4302.   {
  4303.       return s->options &= ~op;
  4304. > }
  4305.   
  4306.   STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s)

test/handshake_helper.c:187:9: 
185.            */
186.           SSL_clear_options(s, 0xFFFFFFFFL);
187. >         SSL_set_options(s, SSL_CTX_get_options(new_ctx));
188.   
189.           ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;

ssl/ssl_lib.c:4276:1: start of procedure SSL_CTX_get_options()
  4274.    * control interface.
  4275.    */
  4276. > unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4277.   {
  4278.       return ctx->options;

ssl/ssl_lib.c:4278:5: 
  4276.   unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4277.   {
  4278. >     return ctx->options;
  4279.   }
  4280.   

ssl/ssl_lib.c:4279:1: return from a call to SSL_CTX_get_options
  4277.   {
  4278.       return ctx->options;
  4279. > }
  4280.   
  4281.   unsigned long SSL_get_options(const SSL *s)

ssl/ssl_lib.c:4291:1: start of procedure SSL_set_options()
  4289.   }
  4290.   
  4291. > unsigned long SSL_set_options(SSL *s, unsigned long op)
  4292.   {
  4293.       return s->options |= op;

ssl/ssl_lib.c:4293:5: 
  4291.   unsigned long SSL_set_options(SSL *s, unsigned long op)
  4292.   {
  4293. >     return s->options |= op;
  4294.   }
  4295.   

ssl/ssl_lib.c:4294:1: return from a call to SSL_set_options
  4292.   {
  4293.       return s->options |= op;
  4294. > }
  4295.   
  4296.   unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op)

test/handshake_helper.c:189:9: 
187.           SSL_set_options(s, SSL_CTX_get_options(new_ctx));
188.   
189. >         ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
190.           return 1;
191.       } else if (len == strlen("server1") &&
