crypto/hmac/hmac.c:263: error: USE_AFTER_FREE
  call to `HMAC_Init_ex()` eventually accesses memory that was invalidated by call to `free()` on line 255 indirectly during the call to `HMAC_CTX_new()`.
Showing all 25 steps of the trace


crypto/hmac/hmac.c:255:14: invalidation part of the trace starts here
253.       if (md == NULL)
254.           md = m;
255.       if ((c = HMAC_CTX_new()) == NULL)
                    ^
256.           goto err;
257.   

crypto/hmac/hmac.c:255:14: when calling `HMAC_CTX_new` here
  253.       if (md == NULL)
  254.           md = m;
  255.       if ((c = HMAC_CTX_new()) == NULL)
                      ^
  256.           goto err;
  257.   

crypto/hmac/hmac.c:174:33: passed as argument to `CRYPTO_zalloc`
    172.   HMAC_CTX *HMAC_CTX_new(void)
    173.   {
    174.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
                                           ^
    175.       if (ctx)
    176.           if (!HMAC_CTX_reset(ctx)) {

crypto/hmac/hmac.c:174:33: return from call to `CRYPTO_zalloc`
    172.   HMAC_CTX *HMAC_CTX_new(void)
    173.   {
    174.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
                                           ^
    175.       if (ctx)
    176.           if (!HMAC_CTX_reset(ctx)) {

crypto/hmac/hmac.c:174:5: assigned
    172.   HMAC_CTX *HMAC_CTX_new(void)
    173.   {
    174.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
               ^
    175.       if (ctx)
    176.           if (!HMAC_CTX_reset(ctx)) {

crypto/hmac/hmac.c:176:14: when calling `HMAC_CTX_reset` here
    174.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
    175.       if (ctx)
    176.           if (!HMAC_CTX_reset(ctx)) {
                        ^
    177.               HMAC_CTX_free(ctx);
    178.               ctx = NULL;

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

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

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

crypto/hmac/hmac.c:187:5: when calling `EVP_MD_CTX_reset` here
        185.       EVP_MD_CTX_reset(ctx->i_ctx);
        186.       EVP_MD_CTX_reset(ctx->o_ctx);
        187.       EVP_MD_CTX_reset(ctx->md_ctx);
                   ^
        188.       ctx->md = NULL;
        189.       ctx->key_length = 0;

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

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

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

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

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/hmac/hmac.c:255:14: use-after-lifetime part of the trace starts here
253.       if (md == NULL)
254.           md = m;
255.       if ((c = HMAC_CTX_new()) == NULL)
                    ^
256.           goto err;
257.   

crypto/hmac/hmac.c:255:14: passed as argument to `HMAC_CTX_new`
  253.       if (md == NULL)
  254.           md = m;
  255.       if ((c = HMAC_CTX_new()) == NULL)
                      ^
  256.           goto err;
  257.   

crypto/hmac/hmac.c:174:33: passed as argument to `CRYPTO_zalloc`
    172.   HMAC_CTX *HMAC_CTX_new(void)
    173.   {
    174.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
                                           ^
    175.       if (ctx)
    176.           if (!HMAC_CTX_reset(ctx)) {

crypto/hmac/hmac.c:174:33: return from call to `CRYPTO_zalloc`
    172.   HMAC_CTX *HMAC_CTX_new(void)
    173.   {
    174.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
                                           ^
    175.       if (ctx)
    176.           if (!HMAC_CTX_reset(ctx)) {

crypto/hmac/hmac.c:174:5: assigned
    172.   HMAC_CTX *HMAC_CTX_new(void)
    173.   {
    174.       HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
               ^
    175.       if (ctx)
    176.           if (!HMAC_CTX_reset(ctx)) {

crypto/hmac/hmac.c:255:14: return from call to `HMAC_CTX_new`
  253.       if (md == NULL)
  254.           md = m;
  255.       if ((c = HMAC_CTX_new()) == NULL)
                      ^
  256.           goto err;
  257.   

crypto/hmac/hmac.c:263:10: when calling `HMAC_Init_ex` here
  261.       }
  262.   
  263.       if (!HMAC_Init_ex(c, key, key_len, evp_md, NULL))
                  ^
  264.           goto err;
  265.       if (!HMAC_Update(c, d, n))

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 char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,\n                    const unsigned char *d, size_t n, unsigned char *md,\n                    unsigned int *md_len)\n{\n    HMAC_CTX *c = NULL;\n    static unsigned char m[EVP_MAX_MD_SIZE];\n    static const unsigned char dummy_key[1] = {'\\0'};\n    if (md == NULL)\n        md = m;\n    if ((c = HMAC_CTX_new()) == NULL)\n        goto err;\n    if (key == NULL && key_len == 0) {\n        key = dummy_key;\n    }\n    if (!HMAC_Init_ex(c, key, key_len, evp_md, NULL))\n        goto err;\n    if (!HMAC_Update(c, d, n))\n        goto err;\n    if (!HMAC_Final(c, md, md_len))\n        goto err;\n    HMAC_CTX_free(c);\n    return md;\n err:\n    HMAC_CTX_free(c);\n    return NULL;\n}", 'HMAC_CTX *HMAC_CTX_new(void)\n{\n    HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));\n    if (ctx)\n        if (!HMAC_CTX_reset(ctx)) {\n            HMAC_CTX_free(ctx);\n            ctx = NULL;\n        }\n    return ctx;\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#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}']