crypto/sm2/sm2_sign.c:145: error: NULL_DEREFERENCE
  pointer `ctx` last assigned on line 66 could be null and is dereferenced by call to `BN_CTX_free()` at line 145, column 5.
Showing all 50 steps of the trace


crypto/sm2/sm2_sign.c:57:1: start of procedure SM2_sig_gen()
55.   }
56.   
57. > static
58.   ECDSA_SIG *SM2_sig_gen(const EC_KEY *key, const BIGNUM *e)
59.   {

crypto/sm2/sm2_sign.c:60:5: 
58.   ECDSA_SIG *SM2_sig_gen(const EC_KEY *key, const BIGNUM *e)
59.   {
60. >     const BIGNUM *dA = EC_KEY_get0_private_key(key);
61.       const EC_GROUP *group = EC_KEY_get0_group(key);
62.       const BIGNUM *order = EC_GROUP_get0_order(group);

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/sm2/sm2_sign.c:61:5: 
59.   {
60.       const BIGNUM *dA = EC_KEY_get0_private_key(key);
61. >     const EC_GROUP *group = EC_KEY_get0_group(key);
62.       const BIGNUM *order = EC_GROUP_get0_order(group);
63.   

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

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

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

crypto/sm2/sm2_sign.c:62:5: 
60.       const BIGNUM *dA = EC_KEY_get0_private_key(key);
61.       const EC_GROUP *group = EC_KEY_get0_group(key);
62. >     const BIGNUM *order = EC_GROUP_get0_order(group);
63.   
64.       ECDSA_SIG *sig = NULL;

crypto/ec/ec_lib.c:328:1: start of procedure EC_GROUP_get0_order()
  326.   }
  327.   
  328. > const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group)
  329.   {
  330.       return group->order;

crypto/ec/ec_lib.c:330:5: 
  328.   const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group)
  329.   {
  330. >     return group->order;
  331.   }
  332.   

crypto/ec/ec_lib.c:331:1: return from a call to EC_GROUP_get0_order
  329.   {
  330.       return group->order;
  331. > }
  332.   
  333.   int EC_GROUP_order_bits(const EC_GROUP *group)

crypto/sm2/sm2_sign.c:64:5: 
62.       const BIGNUM *order = EC_GROUP_get0_order(group);
63.   
64. >     ECDSA_SIG *sig = NULL;
65.       EC_POINT *kG = NULL;
66.       BN_CTX *ctx = NULL;

crypto/sm2/sm2_sign.c:65:5: 
63.   
64.       ECDSA_SIG *sig = NULL;
65. >     EC_POINT *kG = NULL;
66.       BN_CTX *ctx = NULL;
67.       BIGNUM *k = NULL;

crypto/sm2/sm2_sign.c:66:5: 
64.       ECDSA_SIG *sig = NULL;
65.       EC_POINT *kG = NULL;
66. >     BN_CTX *ctx = NULL;
67.       BIGNUM *k = NULL;
68.       BIGNUM *rk = NULL;

crypto/sm2/sm2_sign.c:67:5: 
65.       EC_POINT *kG = NULL;
66.       BN_CTX *ctx = NULL;
67. >     BIGNUM *k = NULL;
68.       BIGNUM *rk = NULL;
69.       BIGNUM *r = NULL;

crypto/sm2/sm2_sign.c:68:5: 
66.       BN_CTX *ctx = NULL;
67.       BIGNUM *k = NULL;
68. >     BIGNUM *rk = NULL;
69.       BIGNUM *r = NULL;
70.       BIGNUM *s = NULL;

crypto/sm2/sm2_sign.c:69:5: 
67.       BIGNUM *k = NULL;
68.       BIGNUM *rk = NULL;
69. >     BIGNUM *r = NULL;
70.       BIGNUM *s = NULL;
71.       BIGNUM *x1 = NULL;

crypto/sm2/sm2_sign.c:70:5: 
68.       BIGNUM *rk = NULL;
69.       BIGNUM *r = NULL;
70. >     BIGNUM *s = NULL;
71.       BIGNUM *x1 = NULL;
72.       BIGNUM *tmp = NULL;

crypto/sm2/sm2_sign.c:71:5: 
69.       BIGNUM *r = NULL;
70.       BIGNUM *s = NULL;
71. >     BIGNUM *x1 = NULL;
72.       BIGNUM *tmp = NULL;
73.   

crypto/sm2/sm2_sign.c:72:5: 
70.       BIGNUM *s = NULL;
71.       BIGNUM *x1 = NULL;
72. >     BIGNUM *tmp = NULL;
73.   
74.       kG = EC_POINT_new(group);

crypto/sm2/sm2_sign.c:74:5: 
72.       BIGNUM *tmp = NULL;
73.   
74. >     kG = EC_POINT_new(group);
75.       if (kG == NULL)
76.           goto done;

crypto/ec/ec_lib.c:552:1: start of procedure EC_POINT_new()
  550.   /* functions for EC_POINT objects */
  551.   
  552. > EC_POINT *EC_POINT_new(const EC_GROUP *group)
  553.   {
  554.       EC_POINT *ret;

crypto/ec/ec_lib.c:556:9: Taking false branch
  554.       EC_POINT *ret;
  555.   
  556.       if (group == NULL) {
                 ^
  557.           ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER);
  558.           return NULL;

crypto/ec/ec_lib.c:560:9: Taking true branch
  558.           return NULL;
  559.       }
  560.       if (group->meth->point_init == 0) {
                 ^
  561.           ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
  562.           return NULL;

crypto/ec/ec_lib.c:561:9: Skipping ERR_put_error(): empty list of specs
  559.       }
  560.       if (group->meth->point_init == 0) {
  561.           ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
                 ^
  562.           return NULL;
  563.       }

crypto/ec/ec_lib.c:562:9: 
  560.       if (group->meth->point_init == 0) {
  561.           ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
  562. >         return NULL;
  563.       }
  564.   

crypto/ec/ec_lib.c:579:1: return from a call to EC_POINT_new
  577.   
  578.       return ret;
  579. > }
  580.   
  581.   void EC_POINT_free(EC_POINT *point)

crypto/sm2/sm2_sign.c:75:9: Taking true branch
73.   
74.       kG = EC_POINT_new(group);
75.       if (kG == NULL)
              ^
76.           goto done;
77.   

crypto/sm2/sm2_sign.c:138:2: 
136.       }
137.   
138. >  done:
139.   
140.       if (sig == NULL) {

crypto/sm2/sm2_sign.c:140:9: Taking true branch
138.    done:
139.   
140.       if (sig == NULL) {
               ^
141.           BN_free(r);
142.           BN_free(s);

crypto/sm2/sm2_sign.c:141:9: Skipping BN_free(): empty list of specs
139.   
140.       if (sig == NULL) {
141.           BN_free(r);
               ^
142.           BN_free(s);
143.       }

crypto/sm2/sm2_sign.c:142:9: Skipping BN_free(): empty list of specs
140.       if (sig == NULL) {
141.           BN_free(r);
142.           BN_free(s);
               ^
143.       }
144.   

crypto/sm2/sm2_sign.c:145:5: 
143.       }
144.   
145. >     BN_CTX_free(ctx);
146.       EC_POINT_free(kG);
147.       return sig;

crypto/bn/bn_ctx.c:157:1: start of procedure BN_CTX_free()
  155.   }
  156.   
  157. > void BN_CTX_free(BN_CTX *ctx)
  158.   {
  159.   #ifdef BN_CTX_DEBUG

crypto/bn/bn_ctx.c:174:5: 
  172.       }
  173.   #endif
  174. >     BN_STACK_finish(&ctx->stack);
  175.       BN_POOL_finish(&ctx->pool);
  176.       OPENSSL_free(ctx);

crypto/bn/bn_ctx.c:243:1: start of procedure BN_STACK_finish()
    241.   }
    242.   
    243. > static void BN_STACK_finish(BN_STACK *st)
    244.   {
    245.       OPENSSL_free(st->indexes);

crypto/bn/bn_ctx.c:245:5: 
    243.   static void BN_STACK_finish(BN_STACK *st)
    244.   {
    245. >     OPENSSL_free(st->indexes);
    246.       st->indexes = NULL;
    247.   }

crypto/mem.c:295:1: start of procedure CRYPTO_free()
      293.   }
      294.   
      295. > void CRYPTO_free(void *str, const char *file, int line)
      296.   {
      297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
      296.   {
      297.       INCREMENT(free_count);
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                     ^
      299.           free_impl(str, file, line);
      300.           return;

crypto/mem.c:298:30: Taking true branch
      296.   {
      297.       INCREMENT(free_count);
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                          ^
      299.           free_impl(str, file, line);
      300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
      297.       INCREMENT(free_count);
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
      299.           free_impl(str, file, line);
                     ^
      300.           return;
      301.       }

crypto/mem.c:300:9: 
      298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
      299.           free_impl(str, file, line);
      300. >         return;
      301.       }
      302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
      312.       free(str);
      313.   #endif
      314. > }
      315.   
      316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/bn/bn_ctx.c:246:5: 
    244.   {
    245.       OPENSSL_free(st->indexes);
    246. >     st->indexes = NULL;
    247.   }
    248.   

crypto/bn/bn_ctx.c:247:1: return from a call to BN_STACK_finish
    245.       OPENSSL_free(st->indexes);
    246.       st->indexes = NULL;
    247. > }
    248.   
    249.   

crypto/bn/bn_ctx.c:175:5: 
  173.   #endif
  174.       BN_STACK_finish(&ctx->stack);
  175. >     BN_POOL_finish(&ctx->pool);
  176.       OPENSSL_free(ctx);
  177.   }

crypto/bn/bn_ctx.c:284:1: start of procedure BN_POOL_finish()
    282.   }
    283.   
    284. > static void BN_POOL_finish(BN_POOL *p)
    285.   {
    286.       unsigned int loop;

crypto/bn/bn_ctx.c:289:12: Loop condition is false. Leaving loop
    287.       BIGNUM *bn;
    288.   
    289.       while (p->head) {
                      ^
    290.           for (loop = 0, bn = p->head->vals; loop++ < BN_CTX_POOL_SIZE; bn++)
    291.               if (bn->d)
