crypto/ec/ecdh_kdf.c:65: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 31, column 12 is not reachable after line 65, column 5.
Showing all 56 steps of the trace


crypto/ec/ecdh_kdf.c:18:1: start of procedure ECDH_KDF_X9_62()
16.   #define ECDH_KDF_MAX    (1 << 30)
17.   
18. > int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
19.                      const unsigned char *Z, size_t Zlen,
20.                      const unsigned char *sinfo, size_t sinfolen,

crypto/ec/ecdh_kdf.c:23:5: 
21.                      const EVP_MD *md)
22.   {
23. >     EVP_MD_CTX *mctx = NULL;
24.       int rv = 0;
25.       unsigned int i;

crypto/ec/ecdh_kdf.c:24:5: 
22.   {
23.       EVP_MD_CTX *mctx = NULL;
24. >     int rv = 0;
25.       unsigned int i;
26.       size_t mdlen;

crypto/ec/ecdh_kdf.c:28:9: Taking false branch
26.       size_t mdlen;
27.       unsigned char ctr[4];
28.       if (sinfolen > ECDH_KDF_MAX || outlen > ECDH_KDF_MAX
              ^
29.           || Zlen > ECDH_KDF_MAX)
30.           return 0;

crypto/ec/ecdh_kdf.c:28:36: Taking false branch
26.       size_t mdlen;
27.       unsigned char ctr[4];
28.       if (sinfolen > ECDH_KDF_MAX || outlen > ECDH_KDF_MAX
                                         ^
29.           || Zlen > ECDH_KDF_MAX)
30.           return 0;

crypto/ec/ecdh_kdf.c:29:12: Taking false branch
27.       unsigned char ctr[4];
28.       if (sinfolen > ECDH_KDF_MAX || outlen > ECDH_KDF_MAX
29.           || Zlen > ECDH_KDF_MAX)
                 ^
30.           return 0;
31.       mctx = EVP_MD_CTX_new();

crypto/ec/ecdh_kdf.c:31:5: 
29.           || Zlen > ECDH_KDF_MAX)
30.           return 0;
31. >     mctx = EVP_MD_CTX_new();
32.       if (mctx == NULL)
33.           return 0;

crypto/evp/digest.c:44:1: start of procedure EVP_MD_CTX_new()
  42.   }
  43.   
  44. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:46:5: 
  44.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47.   }
  48.   

crypto/mem.c:98:1: start of procedure CRYPTO_zalloc()
    96.   }
    97.   
    98. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:100:5: 
    98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100. >     void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)

crypto/mem.c:71:1: start of procedure CRYPTO_malloc()
      69.   }
      70.   
      71. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      72.   {
      73.       void *ret = NULL;

crypto/mem.c:73:5: 
      71.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      72.   {
      73. >     void *ret = NULL;
      74.   
      75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:75:9: Taking false branch
      73.       void *ret = NULL;
      74.   
      75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                    ^
      76.           return malloc_impl(num, file, line);
      77.   

crypto/mem.c:78:9: Taking false branch
      76.           return malloc_impl(num, file, line);
      77.   
      78.       if (num <= 0)
                    ^
      79.           return NULL;
      80.   

crypto/mem.c:81:5: 
      79.           return NULL;
      80.   
      81. >     allow_customize = 0;
      82.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      83.       if (call_malloc_debug) {

crypto/mem.c:91:5: 
      89.       }
      90.   #else
      91. >     osslargused(file); osslargused(line);
      92.       ret = malloc(num);
      93.   #endif

crypto/mem.c:91:24: 
      89.       }
      90.   #else
      91. >     osslargused(file); osslargused(line);
      92.       ret = malloc(num);
      93.   #endif

crypto/mem.c:92:5: 
      90.   #else
      91.       osslargused(file); osslargused(line);
      92. >     ret = malloc(num);
      93.   #endif
      94.   

crypto/mem.c:95:5: 
      93.   #endif
      94.   
      95. >     return ret;
      96.   }
      97.   

crypto/mem.c:96:1: return from a call to CRYPTO_malloc
      94.   
      95.       return ret;
      96. > }
      97.   
      98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:102:9: Taking true branch
    100.       void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)
                   ^
    103.           memset(ret, 0, num);
    104.       return ret;

crypto/mem.c:103:9: 
    101.   
    102.       if (ret != NULL)
    103. >         memset(ret, 0, num);
    104.       return ret;
    105.   }

crypto/mem.c:104:5: 
    102.       if (ret != NULL)
    103.           memset(ret, 0, num);
    104. >     return ret;
    105.   }
    106.   

crypto/mem.c:105:1: return from a call to CRYPTO_zalloc
    103.           memset(ret, 0, num);
    104.       return ret;
    105. > }
    106.   
    107.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:47:1: return from a call to EVP_MD_CTX_new
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47. > }
  48.   
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

crypto/ec/ecdh_kdf.c:32:9: Taking false branch
30.           return 0;
31.       mctx = EVP_MD_CTX_new();
32.       if (mctx == NULL)
              ^
33.           return 0;
34.       mdlen = EVP_MD_size(md);

crypto/ec/ecdh_kdf.c:34:5: 
32.       if (mctx == NULL)
33.           return 0;
34. >     mdlen = EVP_MD_size(md);
35.       for (i = 1;; i++) {
36.           unsigned char mtmp[EVP_MAX_MD_SIZE];

crypto/evp/evp_lib.c:301:1: start of procedure EVP_MD_size()
  299.   }
  300.   
  301. > int EVP_MD_size(const EVP_MD *md)
  302.   {
  303.       if (!md) {

crypto/evp/evp_lib.c:303:10: Taking false branch
  301.   int EVP_MD_size(const EVP_MD *md)
  302.   {
  303.       if (!md) {
                  ^
  304.           EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);
  305.           return -1;

crypto/evp/evp_lib.c:307:5: 
  305.           return -1;
  306.       }
  307. >     return md->md_size;
  308.   }
  309.   

crypto/evp/evp_lib.c:308:1: return from a call to EVP_MD_size
  306.       }
  307.       return md->md_size;
  308. > }
  309.   
  310.   unsigned long EVP_MD_flags(const EVP_MD *md)

crypto/ec/ecdh_kdf.c:35:10: 
33.           return 0;
34.       mdlen = EVP_MD_size(md);
35. >     for (i = 1;; i++) {
36.           unsigned char mtmp[EVP_MAX_MD_SIZE];
37.           EVP_DigestInit_ex(mctx, md, NULL);

crypto/ec/ecdh_kdf.c:35:14: Loop condition is true. Entering loop body
33.           return 0;
34.       mdlen = EVP_MD_size(md);
35.       for (i = 1;; i++) {
                   ^
36.           unsigned char mtmp[EVP_MAX_MD_SIZE];
37.           EVP_DigestInit_ex(mctx, md, NULL);

crypto/ec/ecdh_kdf.c:37:9: Skipping EVP_DigestInit_ex(): empty list of specs
35.       for (i = 1;; i++) {
36.           unsigned char mtmp[EVP_MAX_MD_SIZE];
37.           EVP_DigestInit_ex(mctx, md, NULL);
              ^
38.           ctr[3] = i & 0xFF;
39.           ctr[2] = (i >> 8) & 0xFF;

crypto/ec/ecdh_kdf.c:38:9: 
36.           unsigned char mtmp[EVP_MAX_MD_SIZE];
37.           EVP_DigestInit_ex(mctx, md, NULL);
38. >         ctr[3] = i & 0xFF;
39.           ctr[2] = (i >> 8) & 0xFF;
40.           ctr[1] = (i >> 16) & 0xFF;

crypto/ec/ecdh_kdf.c:39:9: 
37.           EVP_DigestInit_ex(mctx, md, NULL);
38.           ctr[3] = i & 0xFF;
39. >         ctr[2] = (i >> 8) & 0xFF;
40.           ctr[1] = (i >> 16) & 0xFF;
41.           ctr[0] = (i >> 24) & 0xFF;

crypto/ec/ecdh_kdf.c:40:9: 
38.           ctr[3] = i & 0xFF;
39.           ctr[2] = (i >> 8) & 0xFF;
40. >         ctr[1] = (i >> 16) & 0xFF;
41.           ctr[0] = (i >> 24) & 0xFF;
42.           if (!EVP_DigestUpdate(mctx, Z, Zlen))

crypto/ec/ecdh_kdf.c:41:9: 
39.           ctr[2] = (i >> 8) & 0xFF;
40.           ctr[1] = (i >> 16) & 0xFF;
41. >         ctr[0] = (i >> 24) & 0xFF;
42.           if (!EVP_DigestUpdate(mctx, Z, Zlen))
43.               goto err;

crypto/ec/ecdh_kdf.c:42:14: 
40.           ctr[1] = (i >> 16) & 0xFF;
41.           ctr[0] = (i >> 24) & 0xFF;
42. >         if (!EVP_DigestUpdate(mctx, Z, Zlen))
43.               goto err;
44.           if (!EVP_DigestUpdate(mctx, ctr, sizeof(ctr)))

crypto/evp/digest.c:146:1: start of procedure EVP_DigestUpdate()
  144.   }
  145.   
  146. > int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
  147.   {
  148.       return ctx->update(ctx, data, count);

crypto/evp/digest.c:148:5: Skipping __function_pointer__(): unresolved function pointer
  146.   int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
  147.   {
  148.       return ctx->update(ctx, data, count);
             ^
  149.   }
  150.   

crypto/evp/digest.c:149:1: return from a call to EVP_DigestUpdate
  147.   {
  148.       return ctx->update(ctx, data, count);
  149. > }
  150.   
  151.   /* The caller can assume that this removes any secret data from the context */

crypto/ec/ecdh_kdf.c:42:14: Taking true branch
40.           ctr[1] = (i >> 16) & 0xFF;
41.           ctr[0] = (i >> 24) & 0xFF;
42.           if (!EVP_DigestUpdate(mctx, Z, Zlen))
                   ^
43.               goto err;
44.           if (!EVP_DigestUpdate(mctx, ctr, sizeof(ctr)))

crypto/ec/ecdh_kdf.c:64:2: 
62.       }
63.       rv = 1;
64. >  err:
65.       EVP_MD_CTX_free(mctx);
66.       return rv;

crypto/ec/ecdh_kdf.c:65:5: 
63.       rv = 1;
64.    err:
65. >     EVP_MD_CTX_free(mctx);
66.       return rv;
67.   }

crypto/evp/digest.c:49:1: start of procedure EVP_MD_CTX_free()
  47.   }
  48.   
  49. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:51:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
            ^
  52.       OPENSSL_free(ctx);
  53.   }

crypto/evp/digest.c:52:5: 
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
  52. >     OPENSSL_free(ctx);
  53.   }
  54.   

crypto/mem.c:163:1: start of procedure CRYPTO_free()
    161.   }
    162.   
    163. > void CRYPTO_free(void *str, const char *file, int line)
    164.   {
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:165:9: Taking true branch
    163.   void CRYPTO_free(void *str, const char *file, int line)
    164.   {
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    166.           free_impl(str, file, line);
    167.           return;

crypto/mem.c:165:30: Taking true branch
    163.   void CRYPTO_free(void *str, const char *file, int line)
    164.   {
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    166.           free_impl(str, file, line);
    167.           return;

crypto/mem.c:166:9: Skipping __function_pointer__(): unresolved function pointer
    164.   {
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    166.           free_impl(str, file, line);
                   ^
    167.           return;
    168.       }

crypto/mem.c:167:9: 
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    166.           free_impl(str, file, line);
    167. >         return;
    168.       }
    169.   

crypto/mem.c:181:1: return from a call to CRYPTO_free
    179.       free(str);
    180.   #endif
    181. > }
    182.   
    183.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:53:1: return from a call to EVP_MD_CTX_free
  51.       EVP_MD_CTX_reset(ctx);
  52.       OPENSSL_free(ctx);
  53. > }
  54.   
  55.   int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)

int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
                   const unsigned char *Z, size_t Zlen,
                   const unsigned char *sinfo, size_t sinfolen,
                   const EVP_MD *md)
{
    EVP_MD_CTX *mctx = NULL;
    int rv = 0;
    unsigned int i;
    size_t mdlen;
    unsigned char ctr[4];
    if (sinfolen > ECDH_KDF_MAX || outlen > ECDH_KDF_MAX
        || Zlen > ECDH_KDF_MAX)
        return 0;
    mctx = EVP_MD_CTX_new();
    if (mctx == NULL)
        return 0;
    mdlen = EVP_MD_size(md);
    for (i = 1;; i++) {
        unsigned char mtmp[EVP_MAX_MD_SIZE];
        EVP_DigestInit_ex(mctx, md, NULL);
        ctr[3] = i & 0xFF;
        ctr[2] = (i >> 8) & 0xFF;
        ctr[1] = (i >> 16) & 0xFF;
        ctr[0] = (i >> 24) & 0xFF;
        if (!EVP_DigestUpdate(mctx, Z, Zlen))
            goto err;
        if (!EVP_DigestUpdate(mctx, ctr, sizeof(ctr)))
            goto err;
        if (!EVP_DigestUpdate(mctx, sinfo, sinfolen))
            goto err;
        if (outlen >= mdlen) {
            if (!EVP_DigestFinal(mctx, out, NULL))
                goto err;
            outlen -= mdlen;
            if (outlen == 0)
                break;
            out += mdlen;
        } else {
            if (!EVP_DigestFinal(mctx, mtmp, NULL))
                goto err;
            memcpy(out, mtmp, outlen);
            OPENSSL_cleanse(mtmp, mdlen);
            break;
        }
    }
    rv = 1;
 err:
    EVP_MD_CTX_free(mctx);
    return rv;
}
['int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,\n                   const unsigned char *Z, size_t Zlen,\n                   const unsigned char *sinfo, size_t sinfolen,\n                   const EVP_MD *md)\n{\n    EVP_MD_CTX *mctx = NULL;\n    int rv = 0;\n    unsigned int i;\n    size_t mdlen;\n    unsigned char ctr[4];\n    if (sinfolen > ECDH_KDF_MAX || outlen > ECDH_KDF_MAX\n        || Zlen > ECDH_KDF_MAX)\n        return 0;\n    mctx = EVP_MD_CTX_new();\n    if (mctx == NULL)\n        return 0;\n    mdlen = EVP_MD_size(md);\n    for (i = 1;; i++) {\n        unsigned char mtmp[EVP_MAX_MD_SIZE];\n        EVP_DigestInit_ex(mctx, md, NULL);\n        ctr[3] = i & 0xFF;\n        ctr[2] = (i >> 8) & 0xFF;\n        ctr[1] = (i >> 16) & 0xFF;\n        ctr[0] = (i >> 24) & 0xFF;\n        if (!EVP_DigestUpdate(mctx, Z, Zlen))\n            goto err;\n        if (!EVP_DigestUpdate(mctx, ctr, sizeof(ctr)))\n            goto err;\n        if (!EVP_DigestUpdate(mctx, sinfo, sinfolen))\n            goto err;\n        if (outlen >= mdlen) {\n            if (!EVP_DigestFinal(mctx, out, NULL))\n                goto err;\n            outlen -= mdlen;\n            if (outlen == 0)\n                break;\n            out += mdlen;\n        } else {\n            if (!EVP_DigestFinal(mctx, mtmp, NULL))\n                goto err;\n            memcpy(out, mtmp, outlen);\n            OPENSSL_cleanse(mtmp, mdlen);\n            break;\n        }\n    }\n    rv = 1;\n err:\n    EVP_MD_CTX_free(mctx);\n    return rv;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'int EVP_MD_size(const EVP_MD *md)\n{\n    if (!md) {\n        EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);\n        return -1;\n    }\n    return md->md_size;\n}', 'int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)\n{\n    return ctx->update(ctx, data, count);\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n    EVP_MD_CTX_reset(ctx);\n    OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\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}']