crypto/x509/x509_cmp.c:267: error: USE_AFTER_FREE
  call to `EVP_MD_CTX_free()` eventually accesses memory that was invalidated by call to `free()` on line 261 indirectly during the call to `EVP_DigestInit_ex()`.
Showing all 16 steps of the trace


crypto/x509/x509_cmp.c:251:26: invalidation part of the trace starts here
249.   unsigned long X509_NAME_hash_old(X509_NAME *x)
250.   {
251.       EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
                                ^
252.       unsigned long ret = 0;
253.       unsigned char md[16];

crypto/x509/x509_cmp.c:251:26: passed as argument to `EVP_MD_CTX_new`
  249.   unsigned long X509_NAME_hash_old(X509_NAME *x)
  250.   {
  251.       EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
                                  ^
  252.       unsigned long ret = 0;
  253.       unsigned char md[16];

crypto/x509/x509_cmp.c:251:26: return from call to `EVP_MD_CTX_new`
  249.   unsigned long X509_NAME_hash_old(X509_NAME *x)
  250.   {
  251.       EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
                                  ^
  252.       unsigned long ret = 0;
  253.       unsigned char md[16];

crypto/x509/x509_cmp.c:251:5: assigned
  249.   unsigned long X509_NAME_hash_old(X509_NAME *x)
  250.   {
  251.       EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
             ^
  252.       unsigned long ret = 0;
  253.       unsigned char md[16];

crypto/x509/x509_cmp.c:261:9: when calling `EVP_DigestInit_ex` here
  259.       i2d_X509_NAME(x, NULL);
  260.       EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
  261.       if (EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL)
                 ^
  262.           && EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length)
  263.           && EVP_DigestFinal_ex(md_ctx, md, NULL))

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

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

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

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

crypto/x509/x509_cmp.c:251:26: use-after-lifetime part of the trace starts here
249.   unsigned long X509_NAME_hash_old(X509_NAME *x)
250.   {
251.       EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
                                ^
252.       unsigned long ret = 0;
253.       unsigned char md[16];

crypto/x509/x509_cmp.c:251:26: passed as argument to `EVP_MD_CTX_new`
  249.   unsigned long X509_NAME_hash_old(X509_NAME *x)
  250.   {
  251.       EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
                                  ^
  252.       unsigned long ret = 0;
  253.       unsigned char md[16];

crypto/x509/x509_cmp.c:251:26: return from call to `EVP_MD_CTX_new`
  249.   unsigned long X509_NAME_hash_old(X509_NAME *x)
  250.   {
  251.       EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
                                  ^
  252.       unsigned long ret = 0;
  253.       unsigned char md[16];

crypto/x509/x509_cmp.c:251:5: assigned
  249.   unsigned long X509_NAME_hash_old(X509_NAME *x)
  250.   {
  251.       EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
             ^
  252.       unsigned long ret = 0;
  253.       unsigned char md[16];

crypto/x509/x509_cmp.c:267:5: when calling `EVP_MD_CTX_free` here
  265.                  ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)
  266.               ) & 0xffffffffL;
  267.       EVP_MD_CTX_free(md_ctx);
             ^
  268.   
  269.       return (ret);

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

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

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
}
['unsigned long X509_NAME_hash_old(X509_NAME *x)\n{\n    EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();\n    unsigned long ret = 0;\n    unsigned char md[16];\n    if (md_ctx == NULL)\n        return ret;\n    i2d_X509_NAME(x, NULL);\n    EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);\n    if (EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL)\n        && EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length)\n        && EVP_DigestFinal_ex(md_ctx, md, NULL))\n        ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) |\n               ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)\n            ) & 0xffffffffL;\n    EVP_MD_CTX_free(md_ctx);\n    return (ret);\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}']