crypto/cms/cms_pwri.c:226: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_malloc()` at line 191, column 16 is not reachable after line 226, column 5.
Showing all 54 steps of the trace


crypto/cms/cms_pwri.c:176:1: start of procedure kek_unwrap_key()
174.    */
175.   
176. > static int kek_unwrap_key(unsigned char *out, size_t *outlen,
177.                             const unsigned char *in, size_t inlen,
178.                             EVP_CIPHER_CTX *ctx)

crypto/cms/cms_pwri.c:180:5: 
178.                             EVP_CIPHER_CTX *ctx)
179.   {
180. >     size_t blocklen = EVP_CIPHER_CTX_block_size(ctx);
181.       unsigned char *tmp;
182.       int outl, rv = 0;

crypto/evp/evp_lib.c:183:1: start of procedure EVP_CIPHER_CTX_block_size()
  181.   }
  182.   
  183. > int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
  184.   {
  185.       return ctx->cipher->block_size;

crypto/evp/evp_lib.c:185:5: 
  183.   int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
  184.   {
  185. >     return ctx->cipher->block_size;
  186.   }
  187.   

crypto/evp/evp_lib.c:186:1: return from a call to EVP_CIPHER_CTX_block_size
  184.   {
  185.       return ctx->cipher->block_size;
  186. > }
  187.   
  188.   int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *e)

crypto/cms/cms_pwri.c:182:5: 
180.       size_t blocklen = EVP_CIPHER_CTX_block_size(ctx);
181.       unsigned char *tmp;
182. >     int outl, rv = 0;
183.       if (inlen < 2 * blocklen) {
184.           /* too small */

crypto/cms/cms_pwri.c:183:9: Taking false branch
181.       unsigned char *tmp;
182.       int outl, rv = 0;
183.       if (inlen < 2 * blocklen) {
               ^
184.           /* too small */
185.           return 0;

crypto/cms/cms_pwri.c:187:9: Taking false branch
185.           return 0;
186.       }
187.       if (inlen % blocklen) {
               ^
188.           /* Invalid size */
189.           return 0;

crypto/cms/cms_pwri.c:191:9: 
189.           return 0;
190.       }
191. >     if ((tmp = OPENSSL_malloc(inlen)) == NULL) {
192.           CMSerr(CMS_F_KEK_UNWRAP_KEY, ERR_R_MALLOC_FAILURE);
193.           return 0;

crypto/mem.c:192:1: start of procedure CRYPTO_malloc()
  190.   #endif
  191.   
  192. > void *CRYPTO_malloc(size_t num, const char *file, int line)
  193.   {
  194.       void *ret = NULL;

crypto/mem.c:194:5: 
  192.   void *CRYPTO_malloc(size_t num, const char *file, int line)
  193.   {
  194. >     void *ret = NULL;
  195.   
  196.       INCREMENT(malloc_count);

crypto/mem.c:197:9: Taking false branch
  195.   
  196.       INCREMENT(malloc_count);
  197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                 ^
  198.           return malloc_impl(num, file, line);
  199.   

crypto/mem.c:200:9: Taking false branch
  198.           return malloc_impl(num, file, line);
  199.   
  200.       if (num == 0)
                 ^
  201.           return NULL;
  202.   

crypto/mem.c:204:9: Taking true branch
  202.   
  203.       FAILTEST();
  204.       if (allow_customize) {
                 ^
  205.           /*
  206.            * Disallow customization after the first allocation. We only set this

crypto/mem.c:210:9: 
  208.            * allocation.
  209.            */
  210. >         allow_customize = 0;
  211.       }
  212.   #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)

crypto/mem.c:221:5: 
  219.       }
  220.   #else
  221. >     (void)(file); (void)(line);
  222.       ret = malloc(num);
  223.   #endif

crypto/mem.c:221:19: 
  219.       }
  220.   #else
  221. >     (void)(file); (void)(line);
  222.       ret = malloc(num);
  223.   #endif

crypto/mem.c:222:5: 
  220.   #else
  221.       (void)(file); (void)(line);
  222. >     ret = malloc(num);
  223.   #endif
  224.   

crypto/mem.c:225:5: 
  223.   #endif
  224.   
  225. >     return ret;
  226.   }
  227.   

crypto/mem.c:226:1: return from a call to CRYPTO_malloc
  224.   
  225.       return ret;
  226. > }
  227.   
  228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/cms/cms_pwri.c:191:9: Taking false branch
189.           return 0;
190.       }
191.       if ((tmp = OPENSSL_malloc(inlen)) == NULL) {
               ^
192.           CMSerr(CMS_F_KEK_UNWRAP_KEY, ERR_R_MALLOC_FAILURE);
193.           return 0;

crypto/cms/cms_pwri.c:196:10: 
194.       }
195.       /* setup IV by decrypting last two blocks */
196. >     if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,
197.                              in + inlen - 2 * blocklen, blocklen * 2)
198.           /*

crypto/evp/evp_enc.c:444:1: start of procedure EVP_DecryptUpdate()
  442.   }
  443.   
  444. > int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
  445.                         const unsigned char *in, int inl)
  446.   {

crypto/evp/evp_enc.c:447:5: 
  445.                         const unsigned char *in, int inl)
  446.   {
  447. >     int fix_len, cmpl = inl;
  448.       unsigned int b;
  449.   

crypto/evp/evp_enc.c:451:9: Taking false branch
  449.   
  450.       /* Prevent accidental use of encryption context when decrypting */
  451.       if (ctx->encrypt) {
                 ^
  452.           EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_INVALID_OPERATION);
  453.           return 0;

crypto/evp/evp_enc.c:456:5: 
  454.       }
  455.   
  456. >     b = ctx->cipher->block_size;
  457.   
  458.       if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))

crypto/evp/evp_enc.c:458:9: 
  456.       b = ctx->cipher->block_size;
  457.   
  458. >     if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))
  459.           cmpl = (cmpl + 7) / 8;
  460.   

crypto/evp/evp_lib.c:562:1: start of procedure EVP_CIPHER_CTX_test_flags()
    560.   }
    561.   
    562. > int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags)
    563.   {
    564.       return (ctx->flags & flags);

crypto/evp/evp_lib.c:564:5: 
    562.   int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags)
    563.   {
    564. >     return (ctx->flags & flags);
    565.   }
    566.   

crypto/evp/evp_lib.c:565:1: return from a call to EVP_CIPHER_CTX_test_flags
    563.   {
    564.       return (ctx->flags & flags);
    565. > }
    566.   
    567.   int EVP_str2ctrl(int (*cb)(void *ctx, int cmd, void *buf, size_t buflen),

crypto/evp/evp_enc.c:458:9: Taking false branch
  456.       b = ctx->cipher->block_size;
  457.   
  458.       if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))
                 ^
  459.           cmpl = (cmpl + 7) / 8;
  460.   

crypto/evp/evp_enc.c:461:9: Taking false branch
  459.           cmpl = (cmpl + 7) / 8;
  460.   
  461.       if (inl <= 0) {
                 ^
  462.           *outl = 0;
  463.           return inl == 0;

crypto/evp/evp_enc.c:466:9: Taking false branch
  464.       }
  465.   
  466.       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
                 ^
  467.           if (b == 1 && is_partially_overlapping(out, in, cmpl)) {
  468.               EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);

crypto/evp/evp_enc.c:481:9: Taking true branch
  479.       }
  480.   
  481.       if (ctx->flags & EVP_CIPH_NO_PADDING)
                 ^
  482.           return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);
  483.   

crypto/evp/evp_enc.c:482:9: Skipping evp_EncryptDecryptUpdate(): empty list of specs
  480.   
  481.       if (ctx->flags & EVP_CIPH_NO_PADDING)
  482.           return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);
                 ^
  483.   
  484.       OPENSSL_assert(b <= sizeof(ctx->final));

crypto/evp/evp_enc.c:517:1: return from a call to EVP_DecryptUpdate
  515.   
  516.       return 1;
  517. > }
  518.   
  519.   int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)

crypto/cms/cms_pwri.c:196:10: Taking true branch
194.       }
195.       /* setup IV by decrypting last two blocks */
196.       if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,
                ^
197.                              in + inlen - 2 * blocklen, blocklen * 2)
198.           /*

crypto/cms/cms_pwri.c:225:2: 
223.       memcpy(out, tmp + 4, *outlen);
224.       rv = 1;
225. >  err:
226.       OPENSSL_clear_free(tmp, inlen);
227.       return rv;

crypto/cms/cms_pwri.c:226:5: 
224.       rv = 1;
225.    err:
226. >     OPENSSL_clear_free(tmp, inlen);
227.       return rv;
228.   

crypto/mem.c:316:1: start of procedure CRYPTO_clear_free()
  314.   }
  315.   
  316. > void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  317.   {
  318.       if (str == NULL)

crypto/mem.c:318:9: Taking false branch
  316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  317.   {
  318.       if (str == NULL)
                 ^
  319.           return;
  320.       if (num)

crypto/mem.c:320:9: Taking true branch
  318.       if (str == NULL)
  319.           return;
  320.       if (num)
                 ^
  321.           OPENSSL_cleanse(str, num);
  322.       CRYPTO_free(str, file, line);

crypto/mem.c:321:9: 
  319.           return;
  320.       if (num)
  321. >         OPENSSL_cleanse(str, num);
  322.       CRYPTO_free(str, file, line);
  323.   }

crypto/mem_clr.c:22:1: start of procedure OPENSSL_cleanse()
    20.   static volatile memset_t memset_func = memset;
    21.   
    22. > void OPENSSL_cleanse(void *ptr, size_t len)
    23.   {
    24.       memset_func(ptr, 0, len);

crypto/mem_clr.c:24:5: Skipping __function_pointer__(): unresolved function pointer
    22.   void OPENSSL_cleanse(void *ptr, size_t len)
    23.   {
    24.       memset_func(ptr, 0, len);
              ^
    25.   }

crypto/mem_clr.c:25:1: return from a call to OPENSSL_cleanse
    23.   {
    24.       memset_func(ptr, 0, len);
    25. > }

crypto/mem.c:322:5: 
  320.       if (num)
  321.           OPENSSL_cleanse(str, num);
  322. >     CRYPTO_free(str, file, line);
  323.   }

crypto/mem.c:295:1: start of procedure CRYPTO_free()
    293.   }
    294.   
    295. > void CRYPTO_free(void *str, const char *file, int line)
    296.   {
    297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:298:30: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
                   ^
    300.           return;
    301.       }

crypto/mem.c:300:9: 
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
    300. >         return;
    301.       }
    302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
    312.       free(str);
    313.   #endif
    314. > }
    315.   
    316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/mem.c:323:1: return from a call to CRYPTO_clear_free
  321.           OPENSSL_cleanse(str, num);
  322.       CRYPTO_free(str, file, line);
  323. > }

static int kek_unwrap_key(unsigned char *out, size_t *outlen,
                          const unsigned char *in, size_t inlen,
                          EVP_CIPHER_CTX *ctx)
{
    size_t blocklen = EVP_CIPHER_CTX_block_size(ctx);
    unsigned char *tmp;
    int outl, rv = 0;
    if (inlen < 2 * blocklen) {
        return 0;
    }
    if (inlen % blocklen) {
        return 0;
    }
    if ((tmp = OPENSSL_malloc(inlen)) == NULL) {
        CMSerr(CMS_F_KEK_UNWRAP_KEY, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,
                           in + inlen - 2 * blocklen, blocklen * 2)
        || !EVP_DecryptUpdate(ctx, tmp, &outl,
                              tmp + inlen - blocklen, blocklen)
        || !EVP_DecryptUpdate(ctx, tmp, &outl, in, inlen - blocklen)
        || !EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, NULL)
        || !EVP_DecryptUpdate(ctx, tmp, &outl, tmp, inlen))
        goto err;
    if (((tmp[1] ^ tmp[4]) & (tmp[2] ^ tmp[5]) & (tmp[3] ^ tmp[6])) != 0xff) {
        goto err;
    }
    if (inlen < (size_t)(tmp[0] - 4)) {
        goto err;
    }
    *outlen = (size_t)tmp[0];
    memcpy(out, tmp + 4, *outlen);
    rv = 1;
 err:
    OPENSSL_clear_free(tmp, inlen);
    return rv;
}
['static int kek_unwrap_key(unsigned char *out, size_t *outlen,\n                          const unsigned char *in, size_t inlen,\n                          EVP_CIPHER_CTX *ctx)\n{\n    size_t blocklen = EVP_CIPHER_CTX_block_size(ctx);\n    unsigned char *tmp;\n    int outl, rv = 0;\n    if (inlen < 2 * blocklen) {\n        return 0;\n    }\n    if (inlen % blocklen) {\n        return 0;\n    }\n    if ((tmp = OPENSSL_malloc(inlen)) == NULL) {\n        CMSerr(CMS_F_KEK_UNWRAP_KEY, ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,\n                           in + inlen - 2 * blocklen, blocklen * 2)\n        || !EVP_DecryptUpdate(ctx, tmp, &outl,\n                              tmp + inlen - blocklen, blocklen)\n        || !EVP_DecryptUpdate(ctx, tmp, &outl, in, inlen - blocklen)\n        || !EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, NULL)\n        || !EVP_DecryptUpdate(ctx, tmp, &outl, tmp, inlen))\n        goto err;\n    if (((tmp[1] ^ tmp[4]) & (tmp[2] ^ tmp[5]) & (tmp[3] ^ tmp[6])) != 0xff) {\n        goto err;\n    }\n    if (inlen < (size_t)(tmp[0] - 4)) {\n        goto err;\n    }\n    *outlen = (size_t)tmp[0];\n    memcpy(out, tmp + 4, *outlen);\n    rv = 1;\n err:\n    OPENSSL_clear_free(tmp, inlen);\n    return rv;\n}', 'int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)\n{\n    return ctx->cipher->block_size;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    if (allow_customize) {\n        allow_customize = 0;\n    }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n                      const unsigned char *in, int inl)\n{\n    int fix_len, cmpl = inl;\n    unsigned int b;\n    if (ctx->encrypt) {\n        EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_INVALID_OPERATION);\n        return 0;\n    }\n    b = ctx->cipher->block_size;\n    if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))\n        cmpl = (cmpl + 7) / 8;\n    if (inl <= 0) {\n        *outl = 0;\n        return inl == 0;\n    }\n    if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\n        if (b == 1 && is_partially_overlapping(out, in, cmpl)) {\n            EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n            return 0;\n        }\n        fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);\n        if (fix_len < 0) {\n            *outl = 0;\n            return 0;\n        } else\n            *outl = fix_len;\n        return 1;\n    }\n    if (ctx->flags & EVP_CIPH_NO_PADDING)\n        return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);\n    OPENSSL_assert(b <= sizeof(ctx->final));\n    if (ctx->final_used) {\n        if (((PTRDIFF_T)out == (PTRDIFF_T)in)\n            || is_partially_overlapping(out, in, b)) {\n            EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n            return 0;\n        }\n        memcpy(out, ctx->final, b);\n        out += b;\n        fix_len = 1;\n    } else\n        fix_len = 0;\n    if (!evp_EncryptDecryptUpdate(ctx, out, outl, in, inl))\n        return 0;\n    if (b > 1 && !ctx->buf_len) {\n        *outl -= b;\n        ctx->final_used = 1;\n        memcpy(ctx->final, &out[*outl], b);\n    } else\n        ctx->final_used = 0;\n    if (fix_len)\n        *outl += b;\n    return 1;\n}', 'int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags)\n{\n    return (ctx->flags & flags);\n}', 'void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)\n{\n    if (str == NULL)\n        return;\n    if (num)\n        OPENSSL_cleanse(str, num);\n    CRYPTO_free(str, file, line);\n}', 'void OPENSSL_cleanse(void *ptr, size_t len)\n{\n    memset_func(ptr, 0, len);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    INCREMENT(free_count);\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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}']