crypto/ecdh/ech_ossl.c:139: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 127 could be null and is dereferenced by call to `EC_GROUP_get_cofactor()` at line 139, column 14.
Showing all 45 steps of the trace


crypto/ecdh/ech_ossl.c:104:1: start of procedure ecdh_compute_key()
102.    * Finally an optional KDF is applied.
103.    */
104. > static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
105.                               EC_KEY *ecdh,
106.                               void *(*KDF) (const void *in, size_t inlen,

crypto/ecdh/ech_ossl.c:110:5: 
108.   {
109.       BN_CTX *ctx;
110. >     EC_POINT *tmp = NULL;
111.       BIGNUM *x = NULL, *y = NULL;
112.       const BIGNUM *priv_key;

crypto/ecdh/ech_ossl.c:111:5: 
109.       BN_CTX *ctx;
110.       EC_POINT *tmp = NULL;
111. >     BIGNUM *x = NULL, *y = NULL;
112.       const BIGNUM *priv_key;
113.       const EC_GROUP *group;

crypto/ecdh/ech_ossl.c:114:5: 
112.       const BIGNUM *priv_key;
113.       const EC_GROUP *group;
114. >     int ret = -1;
115.       size_t buflen, len;
116.       unsigned char *buf = NULL;

crypto/ecdh/ech_ossl.c:116:5: 
114.       int ret = -1;
115.       size_t buflen, len;
116. >     unsigned char *buf = NULL;
117.   
118.       if (outlen > INT_MAX) {

crypto/ecdh/ech_ossl.c:118:9: Taking false branch
116.       unsigned char *buf = NULL;
117.   
118.       if (outlen > INT_MAX) {
               ^
119.           ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); /* sort of,
120.                                                                    * anyway */

crypto/ecdh/ech_ossl.c:124:9: Taking false branch
122.       }
123.   
124.       if ((ctx = BN_CTX_new()) == NULL)
               ^
125.           goto err;
126.       BN_CTX_start(ctx);

crypto/ecdh/ech_ossl.c:126:5: 
124.       if ((ctx = BN_CTX_new()) == NULL)
125.           goto err;
126. >     BN_CTX_start(ctx);
127.       x = BN_CTX_get(ctx);
128.       y = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:240:1: start of procedure BN_CTX_start()
  238.   }
  239.   
  240. > void BN_CTX_start(BN_CTX *ctx)
  241.   {
  242.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_ctx.c:244:9: Taking true branch
  242.       CTXDBG_ENTRY("BN_CTX_start", ctx);
  243.       /* If we're already overflowing ... */
  244.       if (ctx->err_stack || ctx->too_many)
                 ^
  245.           ctx->err_stack++;
  246.       /* (Try to) get a new frame pointer */

crypto/bn/bn_ctx.c:245:9: 
  243.       /* If we're already overflowing ... */
  244.       if (ctx->err_stack || ctx->too_many)
  245. >         ctx->err_stack++;
  246.       /* (Try to) get a new frame pointer */
  247.       else if (!BN_STACK_push(&ctx->stack, ctx->used)) {

crypto/bn/bn_ctx.c:244:5: 
  242.       CTXDBG_ENTRY("BN_CTX_start", ctx);
  243.       /* If we're already overflowing ... */
  244. >     if (ctx->err_stack || ctx->too_many)
  245.           ctx->err_stack++;
  246.       /* (Try to) get a new frame pointer */

crypto/bn/bn_ctx.c:252:1: return from a call to BN_CTX_start
  250.       }
  251.       CTXDBG_EXIT(ctx);
  252. > }
  253.   
  254.   void BN_CTX_end(BN_CTX *ctx)

crypto/ecdh/ech_ossl.c:127:5: 
125.           goto err;
126.       BN_CTX_start(ctx);
127. >     x = BN_CTX_get(ctx);
128.       y = BN_CTX_get(ctx);
129.   

crypto/bn/bn_ctx.c:271:1: start of procedure BN_CTX_get()
  269.   }
  270.   
  271. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
  272.   {
  273.       BIGNUM *ret;

crypto/bn/bn_ctx.c:276:9: Taking true branch
  274.   
  275.       CTXDBG_ENTRY("BN_CTX_get", ctx);
  276.       if (ctx->err_stack || ctx->too_many)
                 ^
  277.           return NULL;
  278.       if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {

crypto/bn/bn_ctx.c:277:9: 
  275.       CTXDBG_ENTRY("BN_CTX_get", ctx);
  276.       if (ctx->err_stack || ctx->too_many)
  277. >         return NULL;
  278.       if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {
  279.           /*

crypto/bn/bn_ctx.c:292:1: return from a call to BN_CTX_get
  290.       CTXDBG_RET(ctx, ret);
  291.       return ret;
  292. > }
  293.   
  294.   /************/

crypto/ecdh/ech_ossl.c:128:5: 
126.       BN_CTX_start(ctx);
127.       x = BN_CTX_get(ctx);
128. >     y = BN_CTX_get(ctx);
129.   
130.       priv_key = EC_KEY_get0_private_key(ecdh);

crypto/bn/bn_ctx.c:271:1: start of procedure BN_CTX_get()
  269.   }
  270.   
  271. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
  272.   {
  273.       BIGNUM *ret;

crypto/bn/bn_ctx.c:276:9: Taking true branch
  274.   
  275.       CTXDBG_ENTRY("BN_CTX_get", ctx);
  276.       if (ctx->err_stack || ctx->too_many)
                 ^
  277.           return NULL;
  278.       if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {

crypto/bn/bn_ctx.c:277:9: 
  275.       CTXDBG_ENTRY("BN_CTX_get", ctx);
  276.       if (ctx->err_stack || ctx->too_many)
  277. >         return NULL;
  278.       if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {
  279.           /*

crypto/bn/bn_ctx.c:292:1: return from a call to BN_CTX_get
  290.       CTXDBG_RET(ctx, ret);
  291.       return ret;
  292. > }
  293.   
  294.   /************/

crypto/ecdh/ech_ossl.c:130:5: 
128.       y = BN_CTX_get(ctx);
129.   
130. >     priv_key = EC_KEY_get0_private_key(ecdh);
131.       if (priv_key == NULL) {
132.           ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_NO_PRIVATE_VALUE);

crypto/ec/ec_key.c:433:1: start of procedure EC_KEY_get0_private_key()
  431.   }
  432.   
  433. > const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
  434.   {
  435.       return key->priv_key;

crypto/ec/ec_key.c:435:5: 
  433.   const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
  434.   {
  435. >     return key->priv_key;
  436.   }
  437.   

crypto/ec/ec_key.c:436:1: return from a call to EC_KEY_get0_private_key
  434.   {
  435.       return key->priv_key;
  436. > }
  437.   
  438.   int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)

crypto/ecdh/ech_ossl.c:131:9: Taking false branch
129.   
130.       priv_key = EC_KEY_get0_private_key(ecdh);
131.       if (priv_key == NULL) {
               ^
132.           ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_NO_PRIVATE_VALUE);
133.           goto err;

crypto/ecdh/ech_ossl.c:136:5: 
134.       }
135.   
136. >     group = EC_KEY_get0_group(ecdh);
137.   
138.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {

crypto/ec/ec_key.c:421:1: start of procedure EC_KEY_get0_group()
  419.   }
  420.   
  421. > const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  422.   {
  423.       return key->group;

crypto/ec/ec_key.c:423:5: 
  421.   const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  422.   {
  423. >     return key->group;
  424.   }
  425.   

crypto/ec/ec_key.c:424:1: return from a call to EC_KEY_get0_group
  422.   {
  423.       return key->group;
  424. > }
  425.   
  426.   int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)

crypto/ecdh/ech_ossl.c:138:9: 
136.       group = EC_KEY_get0_group(ecdh);
137.   
138. >     if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
139.           if (!EC_GROUP_get_cofactor(group, x, ctx) ||
140.               !BN_mul(x, x, priv_key, ctx)) {

crypto/ec/ec_key.c:527:1: start of procedure EC_KEY_get_flags()
  525.   }
  526.   
  527. > int EC_KEY_get_flags(const EC_KEY *key)
  528.   {
  529.       return key->flags;

crypto/ec/ec_key.c:529:5: 
  527.   int EC_KEY_get_flags(const EC_KEY *key)
  528.   {
  529. >     return key->flags;
  530.   }
  531.   

crypto/ec/ec_key.c:530:1: return from a call to EC_KEY_get_flags
  528.   {
  529.       return key->flags;
  530. > }
  531.   
  532.   void EC_KEY_set_flags(EC_KEY *key, int flags)

crypto/ecdh/ech_ossl.c:138:9: Taking true branch
136.       group = EC_KEY_get0_group(ecdh);
137.   
138.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
               ^
139.           if (!EC_GROUP_get_cofactor(group, x, ctx) ||
140.               !BN_mul(x, x, priv_key, ctx)) {

crypto/ecdh/ech_ossl.c:139:14: 
137.   
138.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
139. >         if (!EC_GROUP_get_cofactor(group, x, ctx) ||
140.               !BN_mul(x, x, priv_key, ctx)) {
141.               ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);

crypto/ec/ec_lib.c:333:1: start of procedure EC_GROUP_get_cofactor()
  331.   }
  332.   
  333. > int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
  334.                             BN_CTX *ctx)
  335.   {

crypto/ec/ec_lib.c:336:10: 
  334.                             BN_CTX *ctx)
  335.   {
  336. >     if (!BN_copy(cofactor, group->cofactor))
  337.           return 0;
  338.   

crypto/bn/bn_lib.c:430:1: start of procedure BN_copy()
    428.   }
    429.   
    430. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
    431.   {
    432.       int i;

crypto/bn/bn_lib.c:438:9: Taking false branch
    436.       bn_check_top(b);
    437.   
    438.       if (a == b)
                   ^
    439.           return (a);
    440.       if (bn_wexpand(a, b->top) == NULL)

crypto/bn/bn_lib.c:440:9: 
    438.       if (a == b)
    439.           return (a);
    440. >     if (bn_wexpand(a, b->top) == NULL)
    441.           return (NULL);
    442.   

crypto/bn/bn_lib.c:993:1: start of procedure bn_wexpand()
      991.   }
      992.   
      993. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
      994.   {
      995.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:995:13: 
      993.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
      994.   {
      995. >     return (words <= a->dmax) ? a : bn_expand2(a, words);
      996.   }
      997.   
