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


crypto/ec/ecdh_ossl.c:87:1: start of procedure ossl_ecdh_compute_key()
85.    * Finally an optional KDF is applied.
86.    */
87. > int ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
88.                             EC_KEY *ecdh,
89.                             void *(*KDF) (const void *in, size_t inlen,

crypto/ec/ecdh_ossl.c:93:5: 
91.   {
92.       BN_CTX *ctx;
93. >     EC_POINT *tmp = NULL;
94.       BIGNUM *x = NULL, *y = NULL;
95.       const BIGNUM *priv_key;

crypto/ec/ecdh_ossl.c:94:5: 
92.       BN_CTX *ctx;
93.       EC_POINT *tmp = NULL;
94. >     BIGNUM *x = NULL, *y = NULL;
95.       const BIGNUM *priv_key;
96.       const EC_GROUP *group;

crypto/ec/ecdh_ossl.c:97:5: 
95.       const BIGNUM *priv_key;
96.       const EC_GROUP *group;
97. >     int ret = -1;
98.       size_t buflen, len;
99.       unsigned char *buf = NULL;

crypto/ec/ecdh_ossl.c:99:5: 
97.       int ret = -1;
98.       size_t buflen, len;
99. >     unsigned char *buf = NULL;
100.   
101.       if (outlen > INT_MAX) {

crypto/ec/ecdh_ossl.c:101:9: Taking false branch
99.       unsigned char *buf = NULL;
100.   
101.       if (outlen > INT_MAX) {
               ^
102.           ECerr(EC_F_OSSL_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); /* sort of,
103.                                                                    * anyway */

crypto/ec/ecdh_ossl.c:107:9: Taking false branch
105.       }
106.   
107.       if ((ctx = BN_CTX_new()) == NULL)
               ^
108.           goto err;
109.       BN_CTX_start(ctx);

crypto/ec/ecdh_ossl.c:109:5: 
107.       if ((ctx = BN_CTX_new()) == NULL)
108.           goto err;
109. >     BN_CTX_start(ctx);
110.       x = BN_CTX_get(ctx);
111.       y = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:236:1: start of procedure BN_CTX_start()
  234.   }
  235.   
  236. > void BN_CTX_start(BN_CTX *ctx)
  237.   {
  238.       CTXDBG_ENTRY("BN_CTX_start", ctx);

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

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

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

crypto/bn/bn_ctx.c:248:1: return from a call to BN_CTX_start
  246.       }
  247.       CTXDBG_EXIT(ctx);
  248. > }
  249.   
  250.   void BN_CTX_end(BN_CTX *ctx)

crypto/ec/ecdh_ossl.c:110:5: 
108.           goto err;
109.       BN_CTX_start(ctx);
110. >     x = BN_CTX_get(ctx);
111.       y = BN_CTX_get(ctx);
112.   

crypto/bn/bn_ctx.c:267:1: start of procedure BN_CTX_get()
  265.   }
  266.   
  267. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
  268.   {
  269.       BIGNUM *ret;

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

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

crypto/bn/bn_ctx.c:288:1: return from a call to BN_CTX_get
  286.       CTXDBG_RET(ctx, ret);
  287.       return ret;
  288. > }
  289.   
  290.   /************/

crypto/ec/ecdh_ossl.c:111:5: 
109.       BN_CTX_start(ctx);
110.       x = BN_CTX_get(ctx);
111. >     y = BN_CTX_get(ctx);
112.   
113.       priv_key = EC_KEY_get0_private_key(ecdh);

crypto/bn/bn_ctx.c:267:1: start of procedure BN_CTX_get()
  265.   }
  266.   
  267. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
  268.   {
  269.       BIGNUM *ret;

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

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

crypto/bn/bn_ctx.c:288:1: return from a call to BN_CTX_get
  286.       CTXDBG_RET(ctx, ret);
  287.       return ret;
  288. > }
  289.   
  290.   /************/

crypto/ec/ecdh_ossl.c:113:5: 
111.       y = BN_CTX_get(ctx);
112.   
113. >     priv_key = EC_KEY_get0_private_key(ecdh);
114.       if (priv_key == NULL) {
115.           ECerr(EC_F_OSSL_ECDH_COMPUTE_KEY, EC_R_NO_PRIVATE_VALUE);

crypto/ec/ec_key.c:464:1: start of procedure EC_KEY_get0_private_key()
  462.   }
  463.   
  464. > const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
  465.   {
  466.       return key->priv_key;

crypto/ec/ec_key.c:466:5: 
  464.   const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
  465.   {
  466. >     return key->priv_key;
  467.   }
  468.   

crypto/ec/ec_key.c:467:1: return from a call to EC_KEY_get0_private_key
  465.   {
  466.       return key->priv_key;
  467. > }
  468.   
  469.   int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)

crypto/ec/ecdh_ossl.c:114:9: Taking false branch
112.   
113.       priv_key = EC_KEY_get0_private_key(ecdh);
114.       if (priv_key == NULL) {
               ^
115.           ECerr(EC_F_OSSL_ECDH_COMPUTE_KEY, EC_R_NO_PRIVATE_VALUE);
116.           goto err;

crypto/ec/ecdh_ossl.c:119:5: 
117.       }
118.   
119. >     group = EC_KEY_get0_group(ecdh);
120.   
121.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {

crypto/ec/ec_key.c:450:1: start of procedure EC_KEY_get0_group()
  448.   }
  449.   
  450. > const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  451.   {
  452.       return key->group;

crypto/ec/ec_key.c:452:5: 
  450.   const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  451.   {
  452. >     return key->group;
  453.   }
  454.   

crypto/ec/ec_key.c:453:1: return from a call to EC_KEY_get0_group
  451.   {
  452.       return key->group;
  453. > }
  454.   
  455.   int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)

crypto/ec/ecdh_ossl.c:121:9: 
119.       group = EC_KEY_get0_group(ecdh);
120.   
121. >     if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
122.           if (!EC_GROUP_get_cofactor(group, x, ctx) ||
123.               !BN_mul(x, x, priv_key, ctx)) {

crypto/ec/ec_key.c:564:1: start of procedure EC_KEY_get_flags()
  562.   }
  563.   
  564. > int EC_KEY_get_flags(const EC_KEY *key)
  565.   {
  566.       return key->flags;

crypto/ec/ec_key.c:566:5: 
  564.   int EC_KEY_get_flags(const EC_KEY *key)
  565.   {
  566. >     return key->flags;
  567.   }
  568.   

crypto/ec/ec_key.c:567:1: return from a call to EC_KEY_get_flags
  565.   {
  566.       return key->flags;
  567. > }
  568.   
  569.   void EC_KEY_set_flags(EC_KEY *key, int flags)

crypto/ec/ecdh_ossl.c:121:9: Taking true branch
119.       group = EC_KEY_get0_group(ecdh);
120.   
121.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
               ^
122.           if (!EC_GROUP_get_cofactor(group, x, ctx) ||
123.               !BN_mul(x, x, priv_key, ctx)) {

crypto/ec/ecdh_ossl.c:122:14: 
120.   
121.       if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
122. >         if (!EC_GROUP_get_cofactor(group, x, ctx) ||
123.               !BN_mul(x, x, priv_key, ctx)) {
124.               ECerr(EC_F_OSSL_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);

crypto/ec/ec_lib.c:321:1: start of procedure EC_GROUP_get_cofactor()
  319.   }
  320.   
  321. > int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
  322.                             BN_CTX *ctx)
  323.   {

crypto/ec/ec_lib.c:324:10: 
  322.                             BN_CTX *ctx)
  323.   {
  324. >     if (!BN_copy(cofactor, group->cofactor))
  325.           return 0;
  326.   

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

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

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

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

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