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


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

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

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

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

crypto/ex_data.c:387:1: start of procedure CRYPTO_get_ex_data()
    385.    * particular index in the class used by this variable
    386.    */
    387. > void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    388.   {
    389.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))

crypto/ex_data.c:389:9: Taking true branch
    387.   void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
    388.   {
    389.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
                   ^
    390.           return NULL;
    391.       return sk_void_value(ad->sk, idx);

crypto/ex_data.c:390:9: 
    388.   {
    389.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
    390. >         return NULL;
    391.       return sk_void_value(ad->sk, idx);
    392.   }

crypto/ex_data.c:392:1: return from a call to CRYPTO_get_ex_data
    390.           return NULL;
    391.       return sk_void_value(ad->sk, idx);
    392. > }

ssl/ssl_lib.c:3732:1: return from a call to SSL_get_ex_data
  3730.   {
  3731.       return (CRYPTO_get_ex_data(&s->ex_data, idx));
  3732. > }
  3733.   
  3734.   int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ssl/ssl_lib.c:3585:1: start of procedure SSL_set_SSL_CTX()
  3583.   }
  3584.   
  3585. > SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)
  3586.   {
  3587.       CERT *new_cert;

ssl/ssl_lib.c:3588:9: Taking false branch
  3586.   {
  3587.       CERT *new_cert;
  3588.       if (ssl->ctx == ctx)
                  ^
  3589.           return ssl->ctx;
  3590.       if (ctx == NULL)

ssl/ssl_lib.c:3590:9: Taking false branch
  3588.       if (ssl->ctx == ctx)
  3589.           return ssl->ctx;
  3590.       if (ctx == NULL)
                  ^
  3591.           ctx = ssl->session_ctx;
  3592.       new_cert = ssl_cert_dup(ctx->cert);

ssl/ssl_lib.c:3592:5: Skipping ssl_cert_dup(): empty list of specs
  3590.       if (ctx == NULL)
  3591.           ctx = ssl->session_ctx;
  3592.       new_cert = ssl_cert_dup(ctx->cert);
              ^
  3593.       if (new_cert == NULL) {
  3594.           return NULL;

ssl/ssl_lib.c:3593:9: Taking false branch
  3591.           ctx = ssl->session_ctx;
  3592.       new_cert = ssl_cert_dup(ctx->cert);
  3593.       if (new_cert == NULL) {
                  ^
  3594.           return NULL;
  3595.       }

ssl/ssl_lib.c:3596:5: 
  3594.           return NULL;
  3595.       }
  3596. >     ssl_cert_free(ssl->cert);
  3597.       ssl->cert = new_cert;
  3598.   

ssl/ssl_cert.c:233:1: start of procedure ssl_cert_free()
    231.   }
    232.   
    233. > void ssl_cert_free(CERT *c)
    234.   {
    235.       int i;

ssl/ssl_cert.c:237:9: Taking true branch
    235.       int i;
    236.   
    237.       if (c == NULL)
                   ^
    238.           return;
    239.   

ssl/ssl_cert.c:238:9: 
    236.   
    237.       if (c == NULL)
    238. >         return;
    239.   
    240.       CRYPTO_DOWN_REF(&c->references, &i, c->lock);

ssl/ssl_cert.c:264:1: return from a call to ssl_cert_free
    262.       CRYPTO_THREAD_lock_free(c->lock);
    263.       OPENSSL_free(c);
    264. > }
    265.   
    266.   int ssl_cert_set0_chain(SSL *s, SSL_CTX *ctx, STACK_OF(X509) *chain)

ssl/ssl_lib.c:3597:5: 
  3595.       }
  3596.       ssl_cert_free(ssl->cert);
  3597. >     ssl->cert = new_cert;
  3598.   
  3599.       /*

ssl/ssl_lib.c:3603:5: Condition is true
  3601.        * so setter APIs must prevent invalid lengths from entering the system.
  3602.        */
  3603.       OPENSSL_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx));
              ^
  3604.   
  3605.       /*

ssl/ssl_lib.c:3611:10: Taking false branch
  3609.        * leave it unchanged.
  3610.        */
  3611.       if ((ssl->ctx != NULL) &&
                   ^
  3612.           (ssl->sid_ctx_length == ssl->ctx->sid_ctx_length) &&
  3613.           (memcmp(ssl->sid_ctx, ssl->ctx->sid_ctx, ssl->sid_ctx_length) == 0)) {

ssl/ssl_lib.c:3618:5: 
  3616.       }
  3617.   
  3618. >     SSL_CTX_up_ref(ctx);
  3619.       SSL_CTX_free(ssl->ctx);     /* decrement reference count */
  3620.       ssl->ctx = ctx;

ssl/ssl_lib.c:2768:1: start of procedure SSL_CTX_up_ref()
    2766.   }
    2767.   
    2768. > int SSL_CTX_up_ref(SSL_CTX *ctx)
    2769.   {
    2770.       int i;

ssl/ssl_lib.c:2772:9: 
    2770.       int i;
    2771.   
    2772. >     if (CRYPTO_UP_REF(&ctx->references, &i, ctx->lock) <= 0)
    2773.           return 0;
    2774.   

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:2772:9: Taking false branch
    2770.       int i;
    2771.   
    2772.       if (CRYPTO_UP_REF(&ctx->references, &i, ctx->lock) <= 0)
                    ^
    2773.           return 0;
    2774.   

ssl/ssl_lib.c:2777:14: Condition is false
    2775.       REF_PRINT_COUNT("SSL_CTX", ctx);
    2776.       REF_ASSERT_ISNT(i < 2);
    2777.       return ((i > 1) ? 1 : 0);
                         ^
    2778.   }
    2779.   

ssl/ssl_lib.c:2777:13: 
    2775.       REF_PRINT_COUNT("SSL_CTX", ctx);
    2776.       REF_ASSERT_ISNT(i < 2);
    2777. >     return ((i > 1) ? 1 : 0);
    2778.   }
    2779.   

ssl/ssl_lib.c:2777:5: 
    2775.       REF_PRINT_COUNT("SSL_CTX", ctx);
    2776.       REF_ASSERT_ISNT(i < 2);
    2777. >     return ((i > 1) ? 1 : 0);
    2778.   }
    2779.   

ssl/ssl_lib.c:2778:1: return from a call to SSL_CTX_up_ref
    2776.       REF_ASSERT_ISNT(i < 2);
    2777.       return ((i > 1) ? 1 : 0);
    2778. > }
    2779.   
    2780.   void SSL_CTX_free(SSL_CTX *a)

ssl/ssl_lib.c:3619:5: Skipping SSL_CTX_free(): empty list of specs
  3617.   
  3618.       SSL_CTX_up_ref(ctx);
  3619.       SSL_CTX_free(ssl->ctx);     /* decrement reference count */
              ^
  3620.       ssl->ctx = ctx;
  3621.   

ssl/ssl_lib.c:3620:5: 
  3618.       SSL_CTX_up_ref(ctx);
  3619.       SSL_CTX_free(ssl->ctx);     /* decrement reference count */
  3620. >     ssl->ctx = ctx;
  3621.   
  3622.       return ssl->ctx;

ssl/ssl_lib.c:3622:5: 
  3620.       ssl->ctx = ctx;
  3621.   
  3622. >     return ssl->ctx;
  3623.   }
  3624.   

ssl/ssl_lib.c:3623:1: return from a call to SSL_set_SSL_CTX
  3621.   
  3622.       return ssl->ctx;
  3623. > }
  3624.   
  3625.   int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)

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

ssl/ssl_lib.c:4067:1: start of procedure SSL_clear_options()
  4065.   }
  4066.   
  4067. > unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4068.   {
  4069.       return s->options &= ~op;

ssl/ssl_lib.c:4069:5: 
  4067.   unsigned long SSL_clear_options(SSL *s, unsigned long op)
  4068.   {
  4069. >     return s->options &= ~op;
  4070.   }
  4071.   

ssl/ssl_lib.c:4070:1: return from a call to SSL_clear_options
  4068.   {
  4069.       return s->options &= ~op;
  4070. > }
  4071.   
  4072.   STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s)

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

ssl/ssl_lib.c:4042:1: start of procedure SSL_CTX_get_options()
  4040.    * control interface.
  4041.    */
  4042. > unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4043.   {
  4044.       return ctx->options;

ssl/ssl_lib.c:4044:5: 
  4042.   unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)
  4043.   {
  4044. >     return ctx->options;
  4045.   }
  4046.   

ssl/ssl_lib.c:4045:1: return from a call to SSL_CTX_get_options
  4043.   {
  4044.       return ctx->options;
  4045. > }
  4046.   
  4047.   unsigned long SSL_get_options(const SSL *s)

ssl/ssl_lib.c:4057:1: start of procedure SSL_set_options()
  4055.   }
  4056.   
  4057. > unsigned long SSL_set_options(SSL *s, unsigned long op)
  4058.   {
  4059.       return s->options |= op;

ssl/ssl_lib.c:4059:5: 
  4057.   unsigned long SSL_set_options(SSL *s, unsigned long op)
  4058.   {
  4059. >     return s->options |= op;
  4060.   }
  4061.   

ssl/ssl_lib.c:4060:1: return from a call to SSL_set_options
  4058.   {
  4059.       return s->options |= op;
  4060. > }
  4061.   
  4062.   unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op)

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