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


crypto/ec/ecdh_kdf.c:61:1: start of procedure ECDH_KDF_X9_62()
59.   #define ECDH_KDF_MAX    (1 << 30)
60.   
61. > int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
62.                      const unsigned char *Z, size_t Zlen,
63.                      const unsigned char *sinfo, size_t sinfolen,

crypto/ec/ecdh_kdf.c:66:5: 
64.                      const EVP_MD *md)
65.   {
66. >     EVP_MD_CTX *mctx = NULL;
67.       int rv = 0;
68.       unsigned int i;

crypto/ec/ecdh_kdf.c:67:5: 
65.   {
66.       EVP_MD_CTX *mctx = NULL;
67. >     int rv = 0;
68.       unsigned int i;
69.       size_t mdlen;

crypto/ec/ecdh_kdf.c:71:9: Taking false branch
69.       size_t mdlen;
70.       unsigned char ctr[4];
71.       if (sinfolen > ECDH_KDF_MAX || outlen > ECDH_KDF_MAX
              ^
72.           || Zlen > ECDH_KDF_MAX)
73.           return 0;

crypto/ec/ecdh_kdf.c:71:36: Taking false branch
69.       size_t mdlen;
70.       unsigned char ctr[4];
71.       if (sinfolen > ECDH_KDF_MAX || outlen > ECDH_KDF_MAX
                                         ^
72.           || Zlen > ECDH_KDF_MAX)
73.           return 0;

crypto/ec/ecdh_kdf.c:72:12: Taking false branch
70.       unsigned char ctr[4];
71.       if (sinfolen > ECDH_KDF_MAX || outlen > ECDH_KDF_MAX
72.           || Zlen > ECDH_KDF_MAX)
                 ^
73.           return 0;
74.       mctx = EVP_MD_CTX_new();

crypto/ec/ecdh_kdf.c:74:5: 
72.           || Zlen > ECDH_KDF_MAX)
73.           return 0;
74. >     mctx = EVP_MD_CTX_new();
75.       if (mctx == NULL)
76.           return 0;

crypto/evp/digest.c:152:1: start of procedure EVP_MD_CTX_new()
  150.   }
  151.   
  152. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  153.   {
  154.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:154:5: 
  152.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  153.   {
  154. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  155.   }
  156.   

crypto/mem.c:159:1: start of procedure CRYPTO_zalloc()
    157.   }
    158.   
    159. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    160.   {
    161.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:161:5: 
    159.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    160.   {
    161. >     void *ret = CRYPTO_malloc(num, file, line);
    162.   
    163.       if (ret != NULL)

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      124.           return malloc_impl(num, file, line);
      125.   

crypto/mem.c:126:9: Taking false branch
      124.           return malloc_impl(num, file, line);
      125.   
      126.       if (num <= 0)
                     ^
      127.           return NULL;
      128.   

crypto/mem.c:129:5: 
      127.           return NULL;
      128.   
      129. >     allow_customize = 0;
      130.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      131.       if (call_malloc_debug) {

crypto/mem.c:139:5: 
      137.       }
      138.   #else
      139. >     (void)file;
      140.       (void)line;
      141.       ret = malloc(num);

crypto/mem.c:140:5: 
      138.   #else
      139.       (void)file;
      140. >     (void)line;
      141.       ret = malloc(num);
      142.   #endif

crypto/mem.c:141:5: 
      139.       (void)file;
      140.       (void)line;
      141. >     ret = malloc(num);
      142.   #endif
      143.   

crypto/mem.c:156:5: 
      154.   #endif
      155.   
      156. >     return ret;
      157.   }
      158.   

crypto/mem.c:157:1: return from a call to CRYPTO_malloc
      155.   
      156.       return ret;
      157. > }
      158.   
      159.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:163:9: Taking true branch
    161.       void *ret = CRYPTO_malloc(num, file, line);
    162.   
    163.       if (ret != NULL)
                   ^
    164.           memset(ret, 0, num);
    165.       return ret;

crypto/mem.c:164:9: 
    162.   
    163.       if (ret != NULL)
    164. >         memset(ret, 0, num);
    165.       return ret;
    166.   }

crypto/mem.c:165:5: 
    163.       if (ret != NULL)
    164.           memset(ret, 0, num);
    165. >     return ret;
    166.   }
    167.   

crypto/mem.c:166:1: return from a call to CRYPTO_zalloc
    164.           memset(ret, 0, num);
    165.       return ret;
    166. > }
    167.   
    168.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:155:1: return from a call to EVP_MD_CTX_new
  153.   {
  154.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  155. > }
  156.   
  157.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

crypto/ec/ecdh_kdf.c:75:9: Taking false branch
73.           return 0;
74.       mctx = EVP_MD_CTX_new();
75.       if (mctx == NULL)
              ^
76.           return 0;
77.       mdlen = EVP_MD_size(md);

crypto/ec/ecdh_kdf.c:77:5: 
75.       if (mctx == NULL)
76.           return 0;
77. >     mdlen = EVP_MD_size(md);
78.       for (i = 1;; i++) {
79.           unsigned char mtmp[EVP_MAX_MD_SIZE];

crypto/evp/evp_lib.c:339:1: start of procedure EVP_MD_size()
  337.   }
  338.   
  339. > int EVP_MD_size(const EVP_MD *md)
  340.   {
  341.       if (!md) {

crypto/evp/evp_lib.c:341:10: Taking false branch
  339.   int EVP_MD_size(const EVP_MD *md)
  340.   {
  341.       if (!md) {
                  ^
  342.           EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);
  343.           return -1;

crypto/evp/evp_lib.c:345:5: 
  343.           return -1;
  344.       }
  345. >     return md->md_size;
  346.   }
  347.   

crypto/evp/evp_lib.c:346:1: return from a call to EVP_MD_size
  344.       }
  345.       return md->md_size;
  346. > }
  347.   
  348.   unsigned long EVP_MD_flags(const EVP_MD *md)

crypto/ec/ecdh_kdf.c:78:10: 
76.           return 0;
77.       mdlen = EVP_MD_size(md);
78. >     for (i = 1;; i++) {
79.           unsigned char mtmp[EVP_MAX_MD_SIZE];
80.           EVP_DigestInit_ex(mctx, md, NULL);

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

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

crypto/ec/ecdh_kdf.c:81:9: 
79.           unsigned char mtmp[EVP_MAX_MD_SIZE];
80.           EVP_DigestInit_ex(mctx, md, NULL);
81. >         ctr[3] = i & 0xFF;
82.           ctr[2] = (i >> 8) & 0xFF;
83.           ctr[1] = (i >> 16) & 0xFF;

crypto/ec/ecdh_kdf.c:82:9: 
80.           EVP_DigestInit_ex(mctx, md, NULL);
81.           ctr[3] = i & 0xFF;
82. >         ctr[2] = (i >> 8) & 0xFF;
83.           ctr[1] = (i >> 16) & 0xFF;
84.           ctr[0] = (i >> 24) & 0xFF;

crypto/ec/ecdh_kdf.c:83:9: 
81.           ctr[3] = i & 0xFF;
82.           ctr[2] = (i >> 8) & 0xFF;
83. >         ctr[1] = (i >> 16) & 0xFF;
84.           ctr[0] = (i >> 24) & 0xFF;
85.           if (!EVP_DigestUpdate(mctx, Z, Zlen))

crypto/ec/ecdh_kdf.c:84:9: 
82.           ctr[2] = (i >> 8) & 0xFF;
83.           ctr[1] = (i >> 16) & 0xFF;
84. >         ctr[0] = (i >> 24) & 0xFF;
85.           if (!EVP_DigestUpdate(mctx, Z, Zlen))
86.               goto err;

crypto/ec/ecdh_kdf.c:85:14: 
83.           ctr[1] = (i >> 16) & 0xFF;
84.           ctr[0] = (i >> 24) & 0xFF;
85. >         if (!EVP_DigestUpdate(mctx, Z, Zlen))
86.               goto err;
87.           if (!EVP_DigestUpdate(mctx, ctr, sizeof(ctr)))

crypto/evp/digest.c:254:1: start of procedure EVP_DigestUpdate()
  252.   }
  253.   
  254. > int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
  255.   {
  256.       return ctx->update(ctx, data, count);

crypto/evp/digest.c:256:5: Skipping __function_pointer__(): unresolved function pointer
  254.   int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
  255.   {
  256.       return ctx->update(ctx, data, count);
             ^
  257.   }
  258.   

crypto/evp/digest.c:257:1: return from a call to EVP_DigestUpdate
  255.   {
  256.       return ctx->update(ctx, data, count);
  257. > }
  258.   
  259.   /* The caller can assume that this removes any secret data from the context */

crypto/ec/ecdh_kdf.c:85:14: Taking true branch
83.           ctr[1] = (i >> 16) & 0xFF;
84.           ctr[0] = (i >> 24) & 0xFF;
85.           if (!EVP_DigestUpdate(mctx, Z, Zlen))
                   ^
86.               goto err;
87.           if (!EVP_DigestUpdate(mctx, ctr, sizeof(ctr)))

crypto/ec/ecdh_kdf.c:107:2: 
105.       }
106.       rv = 1;
107. >  err:
108.       EVP_MD_CTX_free(mctx);
109.       return rv;

crypto/ec/ecdh_kdf.c:108:5: 
106.       rv = 1;
107.    err:
108. >     EVP_MD_CTX_free(mctx);
109.       return rv;
110.   }

crypto/evp/digest.c:157:1: start of procedure EVP_MD_CTX_free()
  155.   }
  156.   
  157. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  158.   {
  159.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:159:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  157.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  158.   {
  159.       EVP_MD_CTX_reset(ctx);
             ^
  160.       OPENSSL_free(ctx);
  161.   }

crypto/evp/digest.c:160:5: 
  158.   {
  159.       EVP_MD_CTX_reset(ctx);
  160. >     OPENSSL_free(ctx);
  161.   }
  162.   

crypto/mem.c:225:1: start of procedure CRYPTO_free()
    223.   }
    224.   
    225. > void CRYPTO_free(void *str, const char *file, int line)
    226.   {
    227.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:227:9: Taking true branch
    225.   void CRYPTO_free(void *str, const char *file, int line)
    226.   {
    227.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    228.           free_impl(str, file, line);
    229.           return;

crypto/mem.c:227:30: Taking true branch
    225.   void CRYPTO_free(void *str, const char *file, int line)
    226.   {
    227.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    228.           free_impl(str, file, line);
    229.           return;

crypto/mem.c:228:9: Skipping __function_pointer__(): unresolved function pointer
    226.   {
    227.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    228.           free_impl(str, file, line);
                   ^
    229.           return;
    230.       }

crypto/mem.c:229:9: 
    227.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    228.           free_impl(str, file, line);
    229. >         return;
    230.       }
    231.   

crypto/mem.c:243:1: return from a call to CRYPTO_free
    241.       free(str);
    242.   #endif
    243. > }
    244.   
    245.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:161:1: return from a call to EVP_MD_CTX_free
  159.       EVP_MD_CTX_reset(ctx);
  160.       OPENSSL_free(ctx);
  161. > }
  162.   
  163.   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    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\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}']