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


crypto/sm2/sm2_crypt.c:208:1: start of procedure SM2_decrypt()
206.   }
207.   
208. > int SM2_decrypt(const EC_KEY *key,
209.                   const EVP_MD *digest,
210.                   const uint8_t *ciphertext,

crypto/sm2/sm2_crypt.c:213:5: 
211.                   size_t ciphertext_len, uint8_t *ptext_buf, size_t *ptext_len)
212.   {
213. >     int rc = 0;
214.       int i;
215.   

crypto/sm2/sm2_crypt.c:216:5: 
214.       int i;
215.   
216. >     BN_CTX *ctx = NULL;
217.       const EC_GROUP *group = EC_KEY_get0_group(key);
218.       EC_POINT *C1 = NULL;

crypto/sm2/sm2_crypt.c:217:5: 
215.   
216.       BN_CTX *ctx = NULL;
217. >     const EC_GROUP *group = EC_KEY_get0_group(key);
218.       EC_POINT *C1 = NULL;
219.       struct SM2_Ciphertext_st *sm2_ctext = NULL;

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_crypt.c:218:5: 
216.       BN_CTX *ctx = NULL;
217.       const EC_GROUP *group = EC_KEY_get0_group(key);
218. >     EC_POINT *C1 = NULL;
219.       struct SM2_Ciphertext_st *sm2_ctext = NULL;
220.       BIGNUM *x2 = NULL;

crypto/sm2/sm2_crypt.c:219:5: 
217.       const EC_GROUP *group = EC_KEY_get0_group(key);
218.       EC_POINT *C1 = NULL;
219. >     struct SM2_Ciphertext_st *sm2_ctext = NULL;
220.       BIGNUM *x2 = NULL;
221.       BIGNUM *y2 = NULL;

crypto/sm2/sm2_crypt.c:220:5: 
218.       EC_POINT *C1 = NULL;
219.       struct SM2_Ciphertext_st *sm2_ctext = NULL;
220. >     BIGNUM *x2 = NULL;
221.       BIGNUM *y2 = NULL;
222.   

crypto/sm2/sm2_crypt.c:221:5: 
219.       struct SM2_Ciphertext_st *sm2_ctext = NULL;
220.       BIGNUM *x2 = NULL;
221. >     BIGNUM *y2 = NULL;
222.   
223.       uint8_t *x2y2 = NULL;

crypto/sm2/sm2_crypt.c:223:5: 
221.       BIGNUM *y2 = NULL;
222.   
223. >     uint8_t *x2y2 = NULL;
224.       uint8_t *computed_C3 = NULL;
225.   

crypto/sm2/sm2_crypt.c:224:5: 
222.   
223.       uint8_t *x2y2 = NULL;
224. >     uint8_t *computed_C3 = NULL;
225.   
226.       const size_t field_size = EC_field_size(group);

crypto/sm2/sm2_crypt.c:226:5: 
224.       uint8_t *computed_C3 = NULL;
225.   
226. >     const size_t field_size = EC_field_size(group);
227.       const int hash_size = EVP_MD_size(digest);
228.   

crypto/sm2/sm2_crypt.c:38:1: start of procedure EC_field_size()
  36.   IMPLEMENT_ASN1_FUNCTIONS(SM2_Ciphertext)
  37.   
  38. > static size_t EC_field_size(const EC_GROUP *group)
  39.   {
  40.       /* Is there some simpler way to do this? */

crypto/sm2/sm2_crypt.c:41:5: Skipping BN_new(): empty list of specs
  39.   {
  40.       /* Is there some simpler way to do this? */
  41.       BIGNUM *p = BN_new();
            ^
  42.       BIGNUM *a = BN_new();
  43.       BIGNUM *b = BN_new();

crypto/sm2/sm2_crypt.c:42:5: Skipping BN_new(): empty list of specs
  40.       /* Is there some simpler way to do this? */
  41.       BIGNUM *p = BN_new();
  42.       BIGNUM *a = BN_new();
            ^
  43.       BIGNUM *b = BN_new();
  44.       size_t field_size = 0;

crypto/sm2/sm2_crypt.c:43:5: Skipping BN_new(): empty list of specs
  41.       BIGNUM *p = BN_new();
  42.       BIGNUM *a = BN_new();
  43.       BIGNUM *b = BN_new();
            ^
  44.       size_t field_size = 0;
  45.   

crypto/sm2/sm2_crypt.c:44:5: 
  42.       BIGNUM *a = BN_new();
  43.       BIGNUM *b = BN_new();
  44. >     size_t field_size = 0;
  45.   
  46.       if (p == NULL || a == NULL || b == NULL)

crypto/sm2/sm2_crypt.c:46:9: Taking false branch
  44.       size_t field_size = 0;
  45.   
  46.       if (p == NULL || a == NULL || b == NULL)
                ^
  47.          goto done;
  48.   

crypto/sm2/sm2_crypt.c:46:22: Taking false branch
  44.       size_t field_size = 0;
  45.   
  46.       if (p == NULL || a == NULL || b == NULL)
                             ^
  47.          goto done;
  48.   

crypto/sm2/sm2_crypt.c:46:35: Taking false branch
  44.       size_t field_size = 0;
  45.   
  46.       if (p == NULL || a == NULL || b == NULL)
                                          ^
  47.          goto done;
  48.   

crypto/sm2/sm2_crypt.c:49:5: 
  47.          goto done;
  48.   
  49. >     EC_GROUP_get_curve_GFp(group, p, a, b, NULL);
  50.       field_size = (BN_num_bits(p) + 7) / 8;
  51.   

crypto/ec/ec_lib.c:424:1: start of procedure EC_GROUP_get_curve_GFp()
    422.   }
    423.   
    424. > int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
    425.                              BIGNUM *b, BN_CTX *ctx)
    426.   {

crypto/ec/ec_lib.c:427:9: Taking true branch
    425.                              BIGNUM *b, BN_CTX *ctx)
    426.   {
    427.       if (group->meth->group_get_curve == 0) {
                   ^
    428.           ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
    429.           return 0;

crypto/ec/ec_lib.c:428:9: Skipping ERR_put_error(): empty list of specs
    426.   {
    427.       if (group->meth->group_get_curve == 0) {
    428.           ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
                   ^
    429.           return 0;
    430.       }

crypto/ec/ec_lib.c:429:9: 
    427.       if (group->meth->group_get_curve == 0) {
    428.           ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
    429. >         return 0;
    430.       }
    431.       return group->meth->group_get_curve(group, p, a, b, ctx);

crypto/ec/ec_lib.c:432:1: return from a call to EC_GROUP_get_curve_GFp
    430.       }
    431.       return group->meth->group_get_curve(group, p, a, b, ctx);
    432. > }
    433.   
    434.   #ifndef OPENSSL_NO_EC2M

crypto/sm2/sm2_crypt.c:50:5: 
  48.   
  49.       EC_GROUP_get_curve_GFp(group, p, a, b, NULL);
  50. >     field_size = (BN_num_bits(p) + 7) / 8;
  51.   
  52.    done:

crypto/bn/bn_lib.c:134:1: start of procedure BN_num_bits()
    132.   }
    133.   
    134. > int BN_num_bits(const BIGNUM *a)
    135.   {
    136.       int i = a->top - 1;

crypto/bn/bn_lib.c:136:5: 
    134.   int BN_num_bits(const BIGNUM *a)
    135.   {
    136. >     int i = a->top - 1;
    137.       bn_check_top(a);
    138.   

crypto/bn/bn_lib.c:139:9: 
    137.       bn_check_top(a);
    138.   
    139. >     if (BN_is_zero(a))
    140.           return 0;
    141.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:814:1: start of procedure BN_is_zero()
      812.   }
      813.   
      814. > int BN_is_zero(const BIGNUM *a)
      815.   {
      816.       return a->top == 0;

crypto/bn/bn_lib.c:816:12: Condition is true
      814.   int BN_is_zero(const BIGNUM *a)
      815.   {
      816.       return a->top == 0;
                        ^
      817.   }
      818.   

crypto/bn/bn_lib.c:816:5: 
      814.   int BN_is_zero(const BIGNUM *a)
      815.   {
      816. >     return a->top == 0;
      817.   }
      818.   

crypto/bn/bn_lib.c:817:1: return from a call to BN_is_zero
      815.   {
      816.       return a->top == 0;
      817. > }
      818.   
      819.   int BN_is_one(const BIGNUM *a)

crypto/bn/bn_lib.c:139:9: Taking true branch
    137.       bn_check_top(a);
    138.   
    139.       if (BN_is_zero(a))
                   ^
    140.           return 0;
    141.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:140:9: 
    138.   
    139.       if (BN_is_zero(a))
    140. >         return 0;
    141.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
    142.   }

crypto/bn/bn_lib.c:142:1: return from a call to BN_num_bits
    140.           return 0;
    141.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
    142. > }
    143.   
    144.   static void bn_free_d(BIGNUM *a)

crypto/sm2/sm2_crypt.c:52:2: 
  50.       field_size = (BN_num_bits(p) + 7) / 8;
  51.   
  52. >  done:
  53.       BN_free(p);
  54.       BN_free(a);

crypto/sm2/sm2_crypt.c:53:5: Skipping BN_free(): empty list of specs
  51.   
  52.    done:
  53.       BN_free(p);
            ^
  54.       BN_free(a);
  55.       BN_free(b);

crypto/sm2/sm2_crypt.c:54:5: Skipping BN_free(): empty list of specs
  52.    done:
  53.       BN_free(p);
  54.       BN_free(a);
            ^
  55.       BN_free(b);
  56.   

crypto/sm2/sm2_crypt.c:55:5: Skipping BN_free(): empty list of specs
  53.       BN_free(p);
  54.       BN_free(a);
  55.       BN_free(b);
            ^
  56.   
  57.       return field_size;

crypto/sm2/sm2_crypt.c:57:5: 
  55.       BN_free(b);
  56.   
  57. >     return field_size;
  58.   }
  59.   

crypto/sm2/sm2_crypt.c:58:1: return from a call to EC_field_size
  56.   
  57.       return field_size;
  58. > }
  59.   
  60.   size_t SM2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len)

crypto/sm2/sm2_crypt.c:227:5: 
225.   
226.       const size_t field_size = EC_field_size(group);
227. >     const int hash_size = EVP_MD_size(digest);
228.   
229.       uint8_t *msg_mask = NULL;

crypto/evp/evp_lib.c:301:1: start of procedure EVP_MD_size()
  299.   }
  300.   
  301. > int EVP_MD_size(const EVP_MD *md)
  302.   {
  303.       if (!md) {

crypto/evp/evp_lib.c:303:10: Taking false branch
  301.   int EVP_MD_size(const EVP_MD *md)
  302.   {
  303.       if (!md) {
                  ^
  304.           EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);
  305.           return -1;

crypto/evp/evp_lib.c:307:5: 
  305.           return -1;
  306.       }
  307. >     return md->md_size;
  308.   }
  309.   

crypto/evp/evp_lib.c:308:1: return from a call to EVP_MD_size
  306.       }
  307.       return md->md_size;
  308. > }
  309.   
  310.   unsigned long EVP_MD_flags(const EVP_MD *md)

crypto/sm2/sm2_crypt.c:229:5: 
227.       const int hash_size = EVP_MD_size(digest);
228.   
229. >     uint8_t *msg_mask = NULL;
230.       const uint8_t *C2 = NULL;
231.       const uint8_t *C3 = NULL;

crypto/sm2/sm2_crypt.c:230:5: 
228.   
229.       uint8_t *msg_mask = NULL;
230. >     const uint8_t *C2 = NULL;
231.       const uint8_t *C3 = NULL;
232.       int msg_len = 0;

crypto/sm2/sm2_crypt.c:231:5: 
229.       uint8_t *msg_mask = NULL;
230.       const uint8_t *C2 = NULL;
231. >     const uint8_t *C3 = NULL;
232.       int msg_len = 0;
233.       EVP_MD_CTX *hash = NULL;

crypto/sm2/sm2_crypt.c:232:5: 
230.       const uint8_t *C2 = NULL;
231.       const uint8_t *C3 = NULL;
232. >     int msg_len = 0;
233.       EVP_MD_CTX *hash = NULL;
234.   

crypto/sm2/sm2_crypt.c:233:5: 
231.       const uint8_t *C3 = NULL;
232.       int msg_len = 0;
233. >     EVP_MD_CTX *hash = NULL;
234.   
235.       if (field_size == 0 || hash_size == 0)

crypto/sm2/sm2_crypt.c:235:9: Taking true branch
233.       EVP_MD_CTX *hash = NULL;
234.   
235.       if (field_size == 0 || hash_size == 0)
               ^
236.          goto done;
237.   

crypto/sm2/sm2_crypt.c:321:2: 
319.       *ptext_len = msg_len;
320.   
321. >  done:
322.   
323.       if (rc == 0)

crypto/sm2/sm2_crypt.c:323:9: Taking true branch
321.    done:
322.   
323.       if (rc == 0)
               ^
324.           memset(ptext_buf, 0, *ptext_len);
325.   

crypto/sm2/sm2_crypt.c:324:9: 
322.   
323.       if (rc == 0)
324. >         memset(ptext_buf, 0, *ptext_len);
325.   
326.       OPENSSL_free(msg_mask);

crypto/sm2/sm2_crypt.c:326:5: 
324.           memset(ptext_buf, 0, *ptext_len);
325.   
326. >     OPENSSL_free(msg_mask);
327.       OPENSSL_free(x2y2);
328.       OPENSSL_free(computed_C3);

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 false 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:312:5: 
  310.       }
  311.   #else
  312. >     free(str);
  313.   #endif
  314.   }

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/sm2/sm2_crypt.c:327:5: 
325.   
326.       OPENSSL_free(msg_mask);
327. >     OPENSSL_free(x2y2);
328.       OPENSSL_free(computed_C3);
329.       EC_POINT_free(C1);

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/sm2/sm2_crypt.c:328:5: 
326.       OPENSSL_free(msg_mask);
327.       OPENSSL_free(x2y2);
328. >     OPENSSL_free(computed_C3);
329.       EC_POINT_free(C1);
330.       BN_CTX_free(ctx);

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 false 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:312:5: 
  310.       }
  311.   #else
  312. >     free(str);
  313.   #endif
  314.   }

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/sm2/sm2_crypt.c:329:5: 
327.       OPENSSL_free(x2y2);
328.       OPENSSL_free(computed_C3);
329. >     EC_POINT_free(C1);
330.       BN_CTX_free(ctx);
331.       SM2_Ciphertext_free(sm2_ctext);

crypto/ec/ec_lib.c:581:1: start of procedure EC_POINT_free()
  579.   }
  580.   
  581. > void EC_POINT_free(EC_POINT *point)
  582.   {
  583.       if (!point)

crypto/ec/ec_lib.c:583:10: Taking true branch
  581.   void EC_POINT_free(EC_POINT *point)
  582.   {
  583.       if (!point)
                  ^
  584.           return;
  585.   

crypto/ec/ec_lib.c:584:9: 
  582.   {
  583.       if (!point)
  584. >         return;
  585.   
  586.       if (point->meth->point_finish != 0)

crypto/ec/ec_lib.c:589:1: return from a call to EC_POINT_free
  587.           point->meth->point_finish(point);
  588.       OPENSSL_free(point);
  589. > }
  590.   
  591.   void EC_POINT_clear_free(EC_POINT *point)

crypto/sm2/sm2_crypt.c:330:5: 
328.       OPENSSL_free(computed_C3);
329.       EC_POINT_free(C1);
330. >     BN_CTX_free(ctx);
331.       SM2_Ciphertext_free(sm2_ctext);
332.       EVP_MD_CTX_free(hash);

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)
