crypto/evp/m_sigver.c:207: error: USE_AFTER_FREE
  call to `EVP_PKEY_verify()` eventually accesses memory that was invalidated by call to `free()` on line 189 indirectly during the call to `EVP_DigestFinal_ex()`.
Showing all 16 steps of the trace


crypto/evp/m_sigver.c:173:1: invalidation part of the trace starts here
171.   }
172.   
173. > int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
174.                             size_t siglen)
175.   {

crypto/evp/m_sigver.c:173:1: parameter `ctx` of EVP_DigestVerifyFinal
  171.   }
  172.   
  173. > int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
  174.                             size_t siglen)
  175.   {

crypto/evp/m_sigver.c:189:17: when calling `EVP_DigestFinal_ex` here
  187.               r = ctx->pctx->pmeth->verifyctx(ctx->pctx, sig, siglen, ctx);
  188.           else
  189.               r = EVP_DigestFinal_ex(ctx, md, &mdlen);
                         ^
  190.       } else {
  191.           EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();

crypto/evp/digest.c:286:1: parameter `ctx` of EVP_DigestFinal_ex
    284.   
    285.   /* The caller can assume that this removes any secret data from the context */
    286. > int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)
    287.   {
    288.       int ret;

crypto/evp/digest.c:310:5: when calling `EVP_MD_CTX_reset` here
    308.       }
    309.   
    310.       EVP_MD_CTX_reset(ctx);
               ^
    311.   
    312.       return ret;

crypto/evp/digest.c:20:1: parameter `ctx` of EVP_MD_CTX_reset
      18.   
      19.   /* This call frees resources associated with the context */
      20. > int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
      21.   {
      22.       if (ctx == NULL)

crypto/evp/digest.c:59:9: when calling `EVP_PKEY_CTX_free` here
      57.        */
      58.       if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
      59.           EVP_PKEY_CTX_free(ctx->pctx);
                    ^
      60.   #ifndef OPENSSL_NO_ENGINE
      61.       ENGINE_finish(ctx->engine);

crypto/evp/pmeth_lib.c:352:1: parameter `ctx` of EVP_PKEY_CTX_free
        350.   }
        351.   
        352. > void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
        353.   {
        354.       if (ctx == NULL)

crypto/evp/pmeth_lib.c:363:5: when calling `CRYPTO_free` here
        361.       ENGINE_finish(ctx->engine);
        362.   #endif
        363.       OPENSSL_free(ctx);
                   ^
        364.   }
        365.   

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

crypto/mem.c:312:5: was invalidated by call to `free()`
          310.       }
          311.   #else
          312.       free(str);
                     ^
          313.   #endif
          314.   }

crypto/evp/m_sigver.c:173:1: use-after-lifetime part of the trace starts here
171.   }
172.   
173. > int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
174.                             size_t siglen)
175.   {

crypto/evp/m_sigver.c:173:1: parameter `ctx` of EVP_DigestVerifyFinal
  171.   }
  172.   
  173. > int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
  174.                             size_t siglen)
  175.   {

crypto/evp/m_sigver.c:207:12: when calling `EVP_PKEY_verify` here
  205.       if (vctx || !r)
  206.           return r;
  207.       return EVP_PKEY_verify(ctx->pctx, sig, siglen, md, mdlen);
                    ^
  208.   }
  209.   

crypto/evp/pmeth_fn.c:86:1: parameter `ctx` of EVP_PKEY_verify
    84.   }
    85.   
    86. > int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
    87.                       const unsigned char *sig, size_t siglen,
    88.                       const unsigned char *tbs, size_t tbslen)

crypto/evp/pmeth_fn.c:90:33: invalid access occurs here
    88.                       const unsigned char *tbs, size_t tbslen)
    89.   {
    90.       if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) {
                                          ^
    91.           EVPerr(EVP_F_EVP_PKEY_VERIFY,
    92.                  EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);

int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
                    const unsigned char *sig, size_t siglen,
                    const unsigned char *tbs, size_t tbslen)
{
    if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) {
        EVPerr(EVP_F_EVP_PKEY_VERIFY,
               EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
        return -2;
    }
    if (ctx->operation != EVP_PKEY_OP_VERIFY) {
        EVPerr(EVP_F_EVP_PKEY_VERIFY, EVP_R_OPERATON_NOT_INITIALIZED);
        return -1;
    }
    return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen);
}
['int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,\n                          size_t siglen)\n{\n    unsigned char md[EVP_MAX_MD_SIZE];\n    int r = 0;\n    unsigned int mdlen = 0;\n    int vctx = 0;\n    if (ctx->pctx->pmeth->verifyctx)\n        vctx = 1;\n    else\n        vctx = 0;\n    if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {\n        if (vctx)\n            r = ctx->pctx->pmeth->verifyctx(ctx->pctx, sig, siglen, ctx);\n        else\n            r = EVP_DigestFinal_ex(ctx, md, &mdlen);\n    } else {\n        EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();\n        if (tmp_ctx == NULL)\n            return -1;\n        if (!EVP_MD_CTX_copy_ex(tmp_ctx, ctx)) {\n            EVP_MD_CTX_free(tmp_ctx);\n            return -1;\n        }\n        if (vctx)\n            r = tmp_ctx->pctx->pmeth->verifyctx(tmp_ctx->pctx,\n                                                sig, siglen, tmp_ctx);\n        else\n            r = EVP_DigestFinal_ex(tmp_ctx, md, &mdlen);\n        EVP_MD_CTX_free(tmp_ctx);\n    }\n    if (vctx || !r)\n        return r;\n    return EVP_PKEY_verify(ctx->pctx, sig, siglen, md, mdlen);\n}', 'int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)\n{\n    int ret;\n    size_t size = 0;\n    if (ctx->digest == NULL || ctx->digest->prov == NULL)\n        goto legacy;\n    if (ctx->digest->dfinal == NULL) {\n        EVPerr(EVP_F_EVP_DIGESTFINAL_EX, EVP_R_FINAL_ERROR);\n        return 0;\n    }\n    ret = ctx->digest->dfinal(ctx->provctx, md, &size);\n    if (isize != NULL) {\n        if (size <= UINT_MAX) {\n            *isize = (int)size;\n        } else {\n            EVPerr(EVP_F_EVP_DIGESTFINAL_EX, EVP_R_FINAL_ERROR);\n            ret = 0;\n        }\n    }\n    EVP_MD_CTX_reset(ctx);\n    return ret;\n legacy:\n    OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);\n    ret = ctx->digest->final(ctx, md);\n    if (isize != NULL)\n        *isize = ctx->digest->md_size;\n    if (ctx->digest->cleanup) {\n        ctx->digest->cleanup(ctx);\n        EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);\n    }\n    OPENSSL_cleanse(ctx->md_data, ctx->digest->ctx_size);\n    return ret;\n}', 'int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)\n{\n    if (ctx == NULL)\n        return 1;\n    if (ctx->digest == NULL || ctx->digest->prov == NULL)\n        goto legacy;\n    if (ctx->provctx != NULL) {\n        if (ctx->digest->freectx != NULL)\n            ctx->digest->freectx(ctx->provctx);\n        ctx->provctx = NULL;\n        EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);\n    }\n    if (ctx->pctx != NULL)\n        goto legacy;\n    return 1;\n legacy:\n    if (ctx->digest && ctx->digest->cleanup\n        && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))\n        ctx->digest->cleanup(ctx);\n    if (ctx->digest && ctx->digest->ctx_size && ctx->md_data\n        && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {\n        OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);\n    }\n    if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))\n        EVP_PKEY_CTX_free(ctx->pctx);\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_finish(ctx->engine);\n#endif\n    OPENSSL_cleanse(ctx, sizeof(*ctx));\n    return 1;\n}', 'void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)\n{\n    if (ctx == NULL)\n        return;\n    if (ctx->pmeth && ctx->pmeth->cleanup)\n        ctx->pmeth->cleanup(ctx);\n    EVP_PKEY_free(ctx->pkey);\n    EVP_PKEY_free(ctx->peerkey);\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_finish(ctx->engine);\n#endif\n    OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    INCREMENT(free_count);\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0, file, line);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1, file, line);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}', 'int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,\n                    const unsigned char *sig, size_t siglen,\n                    const unsigned char *tbs, size_t tbslen)\n{\n    if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) {\n        EVPerr(EVP_F_EVP_PKEY_VERIFY,\n               EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);\n        return -2;\n    }\n    if (ctx->operation != EVP_PKEY_OP_VERIFY) {\n        EVPerr(EVP_F_EVP_PKEY_VERIFY, EVP_R_OPERATON_NOT_INITIALIZED);\n        return -1;\n    }\n    return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen);\n}']