crypto/cms/cms_sd.c:701: error: USE_AFTER_FREE
  call to `EVP_DigestSignInit()` eventually accesses memory that was invalidated by call to `free()` on line 700 indirectly during the call to `EVP_MD_CTX_reset()`.
Showing all 16 steps of the trace


crypto/cms/cms_sd.c:679:1: invalidation part of the trace starts here
677.   }
678.   
679. > int CMS_SignerInfo_sign(CMS_SignerInfo *si)
680.   {
681.       EVP_MD_CTX *mctx = si->mctx;

crypto/cms/cms_sd.c:679:1: parameter `si` of CMS_SignerInfo_sign
  677.   }
  678.   
  679. > int CMS_SignerInfo_sign(CMS_SignerInfo *si)
  680.   {
  681.       EVP_MD_CTX *mctx = si->mctx;

crypto/cms/cms_sd.c:681:5: assigned
  679.   int CMS_SignerInfo_sign(CMS_SignerInfo *si)
  680.   {
  681.       EVP_MD_CTX *mctx = si->mctx;
             ^
  682.       EVP_PKEY_CTX *pctx;
  683.       unsigned char *abuf = NULL;

crypto/cms/cms_sd.c:700:9: when calling `EVP_MD_CTX_reset` here
  698.           pctx = si->pctx;
  699.       else {
  700.           EVP_MD_CTX_reset(mctx);
                 ^
  701.           if (EVP_DigestSignInit(mctx, &pctx, md, NULL, si->pkey) <= 0)
  702.               goto err;

crypto/evp/digest.c:123:1: parameter `ctx` of EVP_MD_CTX_reset
    121.   
    122.   /* This call frees resources associated with the context */
    123. > int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
    124.   {
    125.       if (ctx == NULL)

crypto/evp/digest.c:137:9: when calling `CRYPTO_clear_free` here
    135.       if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
    136.           && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {
    137.           OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
                   ^
    138.       }
    139.       EVP_PKEY_CTX_free(ctx->pctx);

crypto/mem.c:249:1: parameter `str` of CRYPTO_clear_free
      247.   }
      248.   
      249. > void CRYPTO_clear_free(void *str, size_t num)
      250.   {
      251.       if (str == NULL)

crypto/mem.c:255:5: when calling `CRYPTO_free` here
      253.       if (num)
      254.           OPENSSL_cleanse(str, num);
      255.       CRYPTO_free(str);
                 ^
      256.   }

crypto/mem.c:234:1: parameter `str` of CRYPTO_free
        232.   }
        233.   
        234. > void CRYPTO_free(void *str)
        235.   {
        236.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

crypto/mem.c:245:5: was invalidated by call to `free()`
        243.       }
        244.   #else
        245.       free(str);
                   ^
        246.   #endif
        247.   }

crypto/cms/cms_sd.c:679:1: use-after-lifetime part of the trace starts here
677.   }
678.   
679. > int CMS_SignerInfo_sign(CMS_SignerInfo *si)
680.   {
681.       EVP_MD_CTX *mctx = si->mctx;

crypto/cms/cms_sd.c:679:1: parameter `si` of CMS_SignerInfo_sign
  677.   }
  678.   
  679. > int CMS_SignerInfo_sign(CMS_SignerInfo *si)
  680.   {
  681.       EVP_MD_CTX *mctx = si->mctx;

crypto/cms/cms_sd.c:681:5: assigned
  679.   int CMS_SignerInfo_sign(CMS_SignerInfo *si)
  680.   {
  681.       EVP_MD_CTX *mctx = si->mctx;
             ^
  682.       EVP_PKEY_CTX *pctx;
  683.       unsigned char *abuf = NULL;

crypto/cms/cms_sd.c:701:13: when calling `EVP_DigestSignInit` here
  699.       else {
  700.           EVP_MD_CTX_reset(mctx);
  701.           if (EVP_DigestSignInit(mctx, &pctx, md, NULL, si->pkey) <= 0)
                     ^
  702.               goto err;
  703.       }

crypto/mem.c:234:1: parameter `str` of CRYPTO_free
    232.   }
    233.   
    234. > void CRYPTO_free(void *str)
    235.   {
    236.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

crypto/mem.c:245:5: invalid access occurs here
    243.       }
    244.   #else
    245.       free(str);
               ^
    246.   #endif
    247.   }
