crypto/pkcs12/p12_key.c:132: error: MEMORY_LEAK
  memory dynamically allocated to `return` by call to `EVP_MD_CTX_new()` at line 117, column 11 is not reachable after line 132, column 9.
Showing all 36 steps of the trace


crypto/pkcs12/p12_key.c:102:1: start of procedure PKCS12_key_gen_uni()
100.   }
101.   
102. > int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
103.                          int saltlen, int id, int iter, int n,
104.                          unsigned char *out, const EVP_MD *md_type)

crypto/pkcs12/p12_key.c:106:5: 
104.                          unsigned char *out, const EVP_MD *md_type)
105.   {
106. >     unsigned char *B = NULL, *D = NULL, *I = NULL, *p = NULL, *Ai = NULL;
107.       int Slen, Plen, Ilen, Ijlen;
108.       int i, j, u, v;

crypto/pkcs12/p12_key.c:109:5: 
107.       int Slen, Plen, Ilen, Ijlen;
108.       int i, j, u, v;
109. >     int ret = 0;
110.       BIGNUM *Ij = NULL, *Bpl1 = NULL; /* These hold Ij and B + 1 */
111.       EVP_MD_CTX *ctx = NULL;

crypto/pkcs12/p12_key.c:110:5: 
108.       int i, j, u, v;
109.       int ret = 0;
110. >     BIGNUM *Ij = NULL, *Bpl1 = NULL; /* These hold Ij and B + 1 */
111.       EVP_MD_CTX *ctx = NULL;
112.   #ifdef  DEBUG_KEYGEN

crypto/pkcs12/p12_key.c:111:5: 
109.       int ret = 0;
110.       BIGNUM *Ij = NULL, *Bpl1 = NULL; /* These hold Ij and B + 1 */
111. >     EVP_MD_CTX *ctx = NULL;
112.   #ifdef  DEBUG_KEYGEN
113.       unsigned char *tmpout = out;

crypto/pkcs12/p12_key.c:117:5: 
115.   #endif
116.   
117. >     ctx = EVP_MD_CTX_new();
118.       if (ctx == NULL)
119.           goto err;

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:156:1: start of procedure CRYPTO_zalloc()
    154.   }
    155.   
    156. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:158:5: 
    156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158. >     void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       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 (num <= 0)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (num <= 0)
                     ^
      124.           return NULL;
      125.   

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

crypto/mem.c:136:5: 
      134.       }
      135.   #else
      136. >     (void)file;
      137.       (void)line;
      138.       ret = malloc(num);

crypto/mem.c:137:5: 
      135.   #else
      136.       (void)file;
      137. >     (void)line;
      138.       ret = malloc(num);
      139.   #endif

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

crypto/mem.c:153:5: 
      151.   #endif
      152.   
      153. >     return ret;
      154.   }
      155.   

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

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

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

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

crypto/mem.c:163:1: return from a call to CRYPTO_zalloc
    161.           memset(ret, 0, num);
    162.       return ret;
    163. > }
    164.   
    165.   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/pkcs12/p12_key.c:118:9: Taking false branch
116.   
117.       ctx = EVP_MD_CTX_new();
118.       if (ctx == NULL)
               ^
119.           goto err;
120.   

crypto/pkcs12/p12_key.c:129:5: 
127.       h__dump(salt, saltlen);
128.   #endif
129. >     v = EVP_MD_block_size(md_type);
130.       u = EVP_MD_size(md_type);
131.       if (u < 0)

crypto/evp/evp_lib.c:324:1: start of procedure EVP_MD_block_size()
  322.   }
  323.   
  324. > int EVP_MD_block_size(const EVP_MD *md)
  325.   {
  326.       return md->block_size;

crypto/evp/evp_lib.c:326:5: 
  324.   int EVP_MD_block_size(const EVP_MD *md)
  325.   {
  326. >     return md->block_size;
  327.   }
  328.   

crypto/evp/evp_lib.c:327:1: return from a call to EVP_MD_block_size
  325.   {
  326.       return md->block_size;
  327. > }
  328.   
  329.   int EVP_MD_type(const EVP_MD *md)

crypto/pkcs12/p12_key.c:130:5: 
128.   #endif
129.       v = EVP_MD_block_size(md_type);
130. >     u = EVP_MD_size(md_type);
131.       if (u < 0)
132.           return 0;

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/pkcs12/p12_key.c:131:9: Taking true branch
129.       v = EVP_MD_block_size(md_type);
130.       u = EVP_MD_size(md_type);
131.       if (u < 0)
               ^
132.           return 0;
133.       D = OPENSSL_malloc(v);

crypto/pkcs12/p12_key.c:132:9: 
130.       u = EVP_MD_size(md_type);
131.       if (u < 0)
132. >         return 0;
133.       D = OPENSSL_malloc(v);
134.       Ai = OPENSSL_malloc(u);

int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
                       int saltlen, int id, int iter, int n,
                       unsigned char *out, const EVP_MD *md_type)
{
    unsigned char *B = NULL, *D = NULL, *I = NULL, *p = NULL, *Ai = NULL;
    int Slen, Plen, Ilen, Ijlen;
    int i, j, u, v;
    int ret = 0;
    BIGNUM *Ij = NULL, *Bpl1 = NULL;
    EVP_MD_CTX *ctx = NULL;
#ifdef  DEBUG_KEYGEN
    unsigned char *tmpout = out;
    int tmpn = n;
#endif
    ctx = EVP_MD_CTX_new();
    if (ctx == NULL)
        goto err;
#ifdef  DEBUG_KEYGEN
    fprintf(stderr, "KEYGEN DEBUG\n");
    fprintf(stderr, "ID %d, ITER %d\n", id, iter);
    fprintf(stderr, "Password (length %d):\n", passlen);
    h__dump(pass, passlen);
    fprintf(stderr, "Salt (length %d):\n", saltlen);
    h__dump(salt, saltlen);
#endif
    v = EVP_MD_block_size(md_type);
    u = EVP_MD_size(md_type);
    if (u < 0)
        return 0;
    D = OPENSSL_malloc(v);
    Ai = OPENSSL_malloc(u);
    B = OPENSSL_malloc(v + 1);
    Slen = v * ((saltlen + v - 1) / v);
    if (passlen)
        Plen = v * ((passlen + v - 1) / v);
    else
        Plen = 0;
    Ilen = Slen + Plen;
    I = OPENSSL_malloc(Ilen);
    Ij = BN_new();
    Bpl1 = BN_new();
    if (D == NULL || Ai == NULL || B == NULL || I == NULL || Ij == NULL
            || Bpl1 == NULL)
        goto err;
    for (i = 0; i < v; i++)
        D[i] = id;
    p = I;
    for (i = 0; i < Slen; i++)
        *p++ = salt[i % saltlen];
    for (i = 0; i < Plen; i++)
        *p++ = pass[i % passlen];
    for (;;) {
        if (!EVP_DigestInit_ex(ctx, md_type, NULL)
            || !EVP_DigestUpdate(ctx, D, v)
            || !EVP_DigestUpdate(ctx, I, Ilen)
            || !EVP_DigestFinal_ex(ctx, Ai, NULL))
            goto err;
        for (j = 1; j < iter; j++) {
            if (!EVP_DigestInit_ex(ctx, md_type, NULL)
                || !EVP_DigestUpdate(ctx, Ai, u)
                || !EVP_DigestFinal_ex(ctx, Ai, NULL))
                goto err;
        }
        memcpy(out, Ai, min(n, u));
        if (u >= n) {
#ifdef DEBUG_KEYGEN
            fprintf(stderr, "Output KEY (length %d)\n", tmpn);
            h__dump(tmpout, tmpn);
#endif
            ret = 1;
            goto end;
        }
        n -= u;
        out += u;
        for (j = 0; j < v; j++)
            B[j] = Ai[j % u];
        if (!BN_bin2bn(B, v, Bpl1))
            goto err;
        if (!BN_add_word(Bpl1, 1))
            goto err;
        for (j = 0; j < Ilen; j += v) {
            if (!BN_bin2bn(I + j, v, Ij))
                goto err;
            if (!BN_add(Ij, Ij, Bpl1))
                goto err;
            if (!BN_bn2bin(Ij, B))
                goto err;
            Ijlen = BN_num_bytes(Ij);
            if (Ijlen > v) {
                if (!BN_bn2bin(Ij, B))
                    goto err;
                memcpy(I + j, B + 1, v);
#ifndef PKCS12_BROKEN_KEYGEN
            } else if (Ijlen < v) {
                memset(I + j, 0, v - Ijlen);
                if (!BN_bn2bin(Ij, I + j + v - Ijlen))
                    goto err;
#endif
            } else if (!BN_bn2bin(Ij, I + j))
                goto err;
        }
    }
 err:
    PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI, ERR_R_MALLOC_FAILURE);
 end:
    OPENSSL_free(Ai);
    OPENSSL_free(B);
    OPENSSL_free(D);
    OPENSSL_free(I);
    BN_free(Ij);
    BN_free(Bpl1);
    EVP_MD_CTX_free(ctx);
    return ret;
}
['int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,\n                       int saltlen, int id, int iter, int n,\n                       unsigned char *out, const EVP_MD *md_type)\n{\n    unsigned char *B = NULL, *D = NULL, *I = NULL, *p = NULL, *Ai = NULL;\n    int Slen, Plen, Ilen, Ijlen;\n    int i, j, u, v;\n    int ret = 0;\n    BIGNUM *Ij = NULL, *Bpl1 = NULL;\n    EVP_MD_CTX *ctx = NULL;\n#ifdef  DEBUG_KEYGEN\n    unsigned char *tmpout = out;\n    int tmpn = n;\n#endif\n    ctx = EVP_MD_CTX_new();\n    if (ctx == NULL)\n        goto err;\n#ifdef  DEBUG_KEYGEN\n    fprintf(stderr, "KEYGEN DEBUG\\n");\n    fprintf(stderr, "ID %d, ITER %d\\n", id, iter);\n    fprintf(stderr, "Password (length %d):\\n", passlen);\n    h__dump(pass, passlen);\n    fprintf(stderr, "Salt (length %d):\\n", saltlen);\n    h__dump(salt, saltlen);\n#endif\n    v = EVP_MD_block_size(md_type);\n    u = EVP_MD_size(md_type);\n    if (u < 0)\n        return 0;\n    D = OPENSSL_malloc(v);\n    Ai = OPENSSL_malloc(u);\n    B = OPENSSL_malloc(v + 1);\n    Slen = v * ((saltlen + v - 1) / v);\n    if (passlen)\n        Plen = v * ((passlen + v - 1) / v);\n    else\n        Plen = 0;\n    Ilen = Slen + Plen;\n    I = OPENSSL_malloc(Ilen);\n    Ij = BN_new();\n    Bpl1 = BN_new();\n    if (D == NULL || Ai == NULL || B == NULL || I == NULL || Ij == NULL\n            || Bpl1 == NULL)\n        goto err;\n    for (i = 0; i < v; i++)\n        D[i] = id;\n    p = I;\n    for (i = 0; i < Slen; i++)\n        *p++ = salt[i % saltlen];\n    for (i = 0; i < Plen; i++)\n        *p++ = pass[i % passlen];\n    for (;;) {\n        if (!EVP_DigestInit_ex(ctx, md_type, NULL)\n            || !EVP_DigestUpdate(ctx, D, v)\n            || !EVP_DigestUpdate(ctx, I, Ilen)\n            || !EVP_DigestFinal_ex(ctx, Ai, NULL))\n            goto err;\n        for (j = 1; j < iter; j++) {\n            if (!EVP_DigestInit_ex(ctx, md_type, NULL)\n                || !EVP_DigestUpdate(ctx, Ai, u)\n                || !EVP_DigestFinal_ex(ctx, Ai, NULL))\n                goto err;\n        }\n        memcpy(out, Ai, min(n, u));\n        if (u >= n) {\n#ifdef DEBUG_KEYGEN\n            fprintf(stderr, "Output KEY (length %d)\\n", tmpn);\n            h__dump(tmpout, tmpn);\n#endif\n            ret = 1;\n            goto end;\n        }\n        n -= u;\n        out += u;\n        for (j = 0; j < v; j++)\n            B[j] = Ai[j % u];\n        if (!BN_bin2bn(B, v, Bpl1))\n            goto err;\n        if (!BN_add_word(Bpl1, 1))\n            goto err;\n        for (j = 0; j < Ilen; j += v) {\n            if (!BN_bin2bn(I + j, v, Ij))\n                goto err;\n            if (!BN_add(Ij, Ij, Bpl1))\n                goto err;\n            if (!BN_bn2bin(Ij, B))\n                goto err;\n            Ijlen = BN_num_bytes(Ij);\n            if (Ijlen > v) {\n                if (!BN_bn2bin(Ij, B))\n                    goto err;\n                memcpy(I + j, B + 1, v);\n#ifndef PKCS12_BROKEN_KEYGEN\n            } else if (Ijlen < v) {\n                memset(I + j, 0, v - Ijlen);\n                if (!BN_bn2bin(Ij, I + j + v - Ijlen))\n                    goto err;\n#endif\n            } else if (!BN_bn2bin(Ij, I + j))\n                goto err;\n        }\n    }\n err:\n    PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI, ERR_R_MALLOC_FAILURE);\n end:\n    OPENSSL_free(Ai);\n    OPENSSL_free(B);\n    OPENSSL_free(D);\n    OPENSSL_free(I);\n    BN_free(Ij);\n    BN_free(Bpl1);\n    EVP_MD_CTX_free(ctx);\n    return ret;\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 (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_block_size(const EVP_MD *md)\n{\n    return md->block_size;\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}']