crypto/hmac/hmac.c:231: error: USE_AFTER_FREE
  call to `EVP_MD_CTX_copy_ex()` eventually accesses memory that was invalidated by call to `free()` on line 229 indirectly during the call to `HMAC_CTX_reset()`.
Showing all 18 steps of the trace


crypto/hmac/hmac.c:227:1: invalidation part of the trace starts here
225.   }
226.   
227. > int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
228.   {
229.       if (!HMAC_CTX_reset(dctx))

crypto/hmac/hmac.c:227:1: parameter `dctx` of HMAC_CTX_copy
  225.   }
  226.   
  227. > int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
  228.   {
  229.       if (!HMAC_CTX_reset(dctx))

crypto/hmac/hmac.c:229:10: when calling `HMAC_CTX_reset` here
  227.   int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
  228.   {
  229.       if (!HMAC_CTX_reset(dctx))
                  ^
  230.           goto err;
  231.       if (!EVP_MD_CTX_copy_ex(dctx->i_ctx, sctx->i_ctx))

crypto/hmac/hmac.c:205:1: parameter `ctx` of HMAC_CTX_reset
    203.   }
    204.   
    205. > int HMAC_CTX_reset(HMAC_CTX *ctx)
    206.   {
    207.       hmac_ctx_cleanup(ctx);

crypto/hmac/hmac.c:207:5: when calling `hmac_ctx_cleanup` here
    205.   int HMAC_CTX_reset(HMAC_CTX *ctx)
    206.   {
    207.       hmac_ctx_cleanup(ctx);
               ^
    208.       if (ctx->i_ctx == NULL)
    209.           ctx->i_ctx = EVP_MD_CTX_new();

crypto/hmac/hmac.c:184:1: parameter `ctx` of hmac_ctx_cleanup
      182.   }
      183.   
      184. > static void hmac_ctx_cleanup(HMAC_CTX *ctx)
      185.   {
      186.       EVP_MD_CTX_reset(ctx->i_ctx);

crypto/hmac/hmac.c:186:5: when calling `EVP_MD_CTX_reset` here
      184.   static void hmac_ctx_cleanup(HMAC_CTX *ctx)
      185.   {
      186.       EVP_MD_CTX_reset(ctx->i_ctx);
                 ^
      187.       EVP_MD_CTX_reset(ctx->o_ctx);
      188.       EVP_MD_CTX_reset(ctx->md_ctx);

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.   #ifdef CRYPTO_MDEBUG

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

crypto/hmac/hmac.c:227:1: use-after-lifetime part of the trace starts here
225.   }
226.   
227. > int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
228.   {
229.       if (!HMAC_CTX_reset(dctx))

crypto/hmac/hmac.c:227:1: parameter `dctx` of HMAC_CTX_copy
  225.   }
  226.   
  227. > int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
  228.   {
  229.       if (!HMAC_CTX_reset(dctx))

crypto/hmac/hmac.c:231:10: when calling `EVP_MD_CTX_copy_ex` here
  229.       if (!HMAC_CTX_reset(dctx))
  230.           goto err;
  231.       if (!EVP_MD_CTX_copy_ex(dctx->i_ctx, sctx->i_ctx))
                  ^
  232.           goto err;
  233.       if (!EVP_MD_CTX_copy_ex(dctx->o_ctx, sctx->o_ctx))

crypto/mem.c:234:1: parameter `str` of CRYPTO_free
    232.   }
    233.   
    234. > void CRYPTO_free(void *str)
    235.   {
    236.   #ifdef 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)
{
#ifdef 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
}
['int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)\n{\n    if (!HMAC_CTX_reset(dctx))\n        goto err;\n    if (!EVP_MD_CTX_copy_ex(dctx->i_ctx, sctx->i_ctx))\n        goto err;\n    if (!EVP_MD_CTX_copy_ex(dctx->o_ctx, sctx->o_ctx))\n        goto err;\n    if (!EVP_MD_CTX_copy_ex(dctx->md_ctx, sctx->md_ctx))\n        goto err;\n    memcpy(dctx->key, sctx->key, HMAC_MAX_MD_CBLOCK);\n    dctx->key_length = sctx->key_length;\n    dctx->md = sctx->md;\n    return 1;\n err:\n    hmac_ctx_cleanup(dctx);\n    return 0;\n}', 'int HMAC_CTX_reset(HMAC_CTX *ctx)\n{\n    hmac_ctx_cleanup(ctx);\n    if (ctx->i_ctx == NULL)\n        ctx->i_ctx = EVP_MD_CTX_new();\n    if (ctx->i_ctx == NULL)\n        goto err;\n    if (ctx->o_ctx == NULL)\n        ctx->o_ctx = EVP_MD_CTX_new();\n    if (ctx->o_ctx == NULL)\n        goto err;\n    if (ctx->md_ctx == NULL)\n        ctx->md_ctx = EVP_MD_CTX_new();\n    if (ctx->md_ctx == NULL)\n        goto err;\n    ctx->md = NULL;\n    return 1;\n err:\n    hmac_ctx_cleanup(ctx);\n    return 0;\n}', 'static void hmac_ctx_cleanup(HMAC_CTX *ctx)\n{\n    EVP_MD_CTX_reset(ctx->i_ctx);\n    EVP_MD_CTX_reset(ctx->o_ctx);\n    EVP_MD_CTX_reset(ctx->md_ctx);\n    ctx->md = NULL;\n    ctx->key_length = 0;\n    memset(ctx->key, 0, sizeof(HMAC_MAX_MD_CBLOCK));\n}', 'int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)\n{\n    if (ctx == NULL)\n        return 1;\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    EVP_PKEY_CTX_free(ctx->pctx);\n#ifndef OPENSSL_NO_ENGINE\n    if (ctx->engine)\n        ENGINE_finish(ctx->engine);\n#endif\n    memset(ctx, 0, sizeof(*ctx));\n    return 1;\n}', 'void CRYPTO_clear_free(void *str, size_t num)\n{\n    if (str == NULL)\n        return;\n    if (num)\n        OPENSSL_cleanse(str, num);\n    CRYPTO_free(str);\n}', 'void CRYPTO_free(void *str)\n{\n#ifdef 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}']