ssl/ssl_lib.c:3642: error: USE_AFTER_FREE
  call to `EVP_MD_CTX_free()` eventually accesses memory that was invalidated by call to `free()` on line 3641 indirectly during the call to `EVP_DigestInit_ex()`.
Showing all 16 steps of the trace


ssl/ssl_lib.c:3640:13: invalidation part of the trace starts here
3638.   {
3639.       ssl_clear_hash_ctx(hash);
3640.       *hash = EVP_MD_CTX_new();
                    ^
3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
3642.           EVP_MD_CTX_free(*hash);

ssl/ssl_lib.c:3640:13: passed as argument to `EVP_MD_CTX_new`
  3638.   {
  3639.       ssl_clear_hash_ctx(hash);
  3640.       *hash = EVP_MD_CTX_new();
                      ^
  3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
  3642.           EVP_MD_CTX_free(*hash);

ssl/ssl_lib.c:3640:13: return from call to `EVP_MD_CTX_new`
  3638.   {
  3639.       ssl_clear_hash_ctx(hash);
  3640.       *hash = EVP_MD_CTX_new();
                      ^
  3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
  3642.           EVP_MD_CTX_free(*hash);

ssl/ssl_lib.c:3640:5: assigned
  3638.   {
  3639.       ssl_clear_hash_ctx(hash);
  3640.       *hash = EVP_MD_CTX_new();
              ^
  3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
  3642.           EVP_MD_CTX_free(*hash);

ssl/ssl_lib.c:3641:33: when calling `EVP_DigestInit_ex` here
  3639.       ssl_clear_hash_ctx(hash);
  3640.       *hash = EVP_MD_CTX_new();
  3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
                                          ^
  3642.           EVP_MD_CTX_free(*hash);
  3643.           *hash = NULL;

crypto/evp/digest.c:170:1: parameter `ctx` of EVP_DigestInit_ex
    168.   }
    169.   
    170. > int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
    171.   {
    172.       EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);

crypto/evp/digest.c:229:13: when calling `CRYPTO_free` here
    227.       if (ctx->digest != type) {
    228.           if (ctx->digest && ctx->digest->ctx_size)
    229.               OPENSSL_free(ctx->md_data);
                       ^
    230.           ctx->digest = type;
    231.           if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {

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.   }

ssl/ssl_lib.c:3640:13: use-after-lifetime part of the trace starts here
3638.   {
3639.       ssl_clear_hash_ctx(hash);
3640.       *hash = EVP_MD_CTX_new();
                    ^
3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
3642.           EVP_MD_CTX_free(*hash);

ssl/ssl_lib.c:3640:13: passed as argument to `EVP_MD_CTX_new`
  3638.   {
  3639.       ssl_clear_hash_ctx(hash);
  3640.       *hash = EVP_MD_CTX_new();
                      ^
  3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
  3642.           EVP_MD_CTX_free(*hash);

ssl/ssl_lib.c:3640:13: return from call to `EVP_MD_CTX_new`
  3638.   {
  3639.       ssl_clear_hash_ctx(hash);
  3640.       *hash = EVP_MD_CTX_new();
                      ^
  3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
  3642.           EVP_MD_CTX_free(*hash);

ssl/ssl_lib.c:3640:5: assigned
  3638.   {
  3639.       ssl_clear_hash_ctx(hash);
  3640.       *hash = EVP_MD_CTX_new();
              ^
  3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
  3642.           EVP_MD_CTX_free(*hash);

ssl/ssl_lib.c:3642:9: when calling `EVP_MD_CTX_free` here
  3640.       *hash = EVP_MD_CTX_new();
  3641.       if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
  3642.           EVP_MD_CTX_free(*hash);
                  ^
  3643.           *hash = NULL;
  3644.           return NULL;

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.   }

void CRYPTO_free(void *str)
{
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
    if (call_malloc_debug) {
        CRYPTO_mem_debug_free(str, 0);
        free(str);
        CRYPTO_mem_debug_free(str, 1);
    } else {
        free(str);
    }
#else
    free(str);
#endif
}
['EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md)\n{\n    ssl_clear_hash_ctx(hash);\n    *hash = EVP_MD_CTX_new();\n    if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {\n        EVP_MD_CTX_free(*hash);\n        *hash = NULL;\n        return NULL;\n    }\n    return *hash;\n}', 'int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)\n{\n    EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);\n#ifndef OPENSSL_NO_ENGINE\n    if (ctx->engine && ctx->digest && (!type ||\n                                       (type\n                                        && (type->type ==\n                                            ctx->digest->type))))\n        goto skip_to_init;\n    if (type) {\n        if (ctx->engine)\n            ENGINE_finish(ctx->engine);\n        if (impl) {\n            if (!ENGINE_init(impl)) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n                return 0;\n            }\n        } else\n            impl = ENGINE_get_digest_engine(type->type);\n        if (impl) {\n            const EVP_MD *d = ENGINE_get_digest(impl, type->type);\n            if (!d) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n                ENGINE_finish(impl);\n                return 0;\n            }\n            type = d;\n            ctx->engine = impl;\n        } else\n            ctx->engine = NULL;\n    } else {\n        if (!ctx->digest) {\n            EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_NO_DIGEST_SET);\n            return 0;\n        }\n        type = ctx->digest;\n    }\n#endif\n    if (ctx->digest != type) {\n        if (ctx->digest && ctx->digest->ctx_size)\n            OPENSSL_free(ctx->md_data);\n        ctx->digest = type;\n        if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {\n            ctx->update = type->update;\n            ctx->md_data = OPENSSL_malloc(type->ctx_size);\n            if (ctx->md_data == NULL) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, ERR_R_MALLOC_FAILURE);\n                return 0;\n            }\n        }\n    }\n#ifndef OPENSSL_NO_ENGINE\n skip_to_init:\n#endif\n    if (ctx->pctx) {\n        int r;\n        r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,\n                              EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);\n        if (r <= 0 && (r != -2))\n            return 0;\n    }\n    if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT)\n        return 1;\n    return ctx->digest->init(ctx);\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}']