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


crypto/cms/cms_pwri.c:220:1: start of procedure kek_unwrap_key()
218.    */
219.   
220. > static int kek_unwrap_key(unsigned char *out, size_t *outlen,
221.                             const unsigned char *in, size_t inlen,
222.                             EVP_CIPHER_CTX *ctx)

crypto/cms/cms_pwri.c:224:5: 
222.                             EVP_CIPHER_CTX *ctx)
223.   {
224. >     size_t blocklen = EVP_CIPHER_CTX_block_size(ctx);
225.       unsigned char *tmp;
226.       int outl, rv = 0;

crypto/evp/evp_lib.c:218:1: start of procedure EVP_CIPHER_CTX_block_size()
  216.   }
  217.   
  218. > int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
  219.   {
  220.       return ctx->cipher->block_size;

crypto/evp/evp_lib.c:220:5: 
  218.   int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
  219.   {
  220. >     return ctx->cipher->block_size;
  221.   }
  222.   

crypto/evp/evp_lib.c:221:1: return from a call to EVP_CIPHER_CTX_block_size
  219.   {
  220.       return ctx->cipher->block_size;
  221. > }
  222.   
  223.   int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *e)

crypto/cms/cms_pwri.c:226:5: 
224.       size_t blocklen = EVP_CIPHER_CTX_block_size(ctx);
225.       unsigned char *tmp;
226. >     int outl, rv = 0;
227.       if (inlen < 2 * blocklen) {
228.           /* too small */

crypto/cms/cms_pwri.c:227:9: Taking false branch
225.       unsigned char *tmp;
226.       int outl, rv = 0;
227.       if (inlen < 2 * blocklen) {
               ^
228.           /* too small */
229.           return 0;

crypto/cms/cms_pwri.c:231:9: Taking false branch
229.           return 0;
230.       }
231.       if (inlen % blocklen) {
               ^
232.           /* Invalid size */
233.           return 0;

crypto/cms/cms_pwri.c:235:5: 
233.           return 0;
234.       }
235. >     tmp = OPENSSL_malloc(inlen);
236.       if (tmp == NULL)
237.           return 0;

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. >     osslargused(file); osslargused(line);
  140.       ret = malloc(num);
  141.   #endif

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

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

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

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

crypto/cms/cms_pwri.c:236:9: Taking false branch
234.       }
235.       tmp = OPENSSL_malloc(inlen);
236.       if (tmp == NULL)
               ^
237.           return 0;
238.       /* setup IV by decrypting last two blocks */

crypto/cms/cms_pwri.c:239:10: 
237.           return 0;
238.       /* setup IV by decrypting last two blocks */
239. >     if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,
240.                              in + inlen - 2 * blocklen, blocklen * 2)
241.           /*

crypto/evp/evp_enc.c:422:1: start of procedure EVP_DecryptUpdate()
  420.   }
  421.   
  422. > int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
  423.                         const unsigned char *in, int inl)
  424.   {

crypto/evp/evp_enc.c:428:9: Taking false branch
  426.       unsigned int b;
  427.   
  428.       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
                 ^
  429.           fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
  430.           if (fix_len < 0) {

crypto/evp/evp_enc.c:438:9: Taking true branch
  436.       }
  437.   
  438.       if (inl <= 0) {
                 ^
  439.           *outl = 0;
  440.           return inl == 0;

crypto/evp/evp_enc.c:439:9: 
  437.   
  438.       if (inl <= 0) {
  439. >         *outl = 0;
  440.           return inl == 0;
  441.       }

crypto/evp/evp_enc.c:440:16: Condition is false
  438.       if (inl <= 0) {
  439.           *outl = 0;
  440.           return inl == 0;
                        ^
  441.       }
  442.   

crypto/evp/evp_enc.c:440:9: 
  438.       if (inl <= 0) {
  439.           *outl = 0;
  440. >         return inl == 0;
  441.       }
  442.   

crypto/evp/evp_enc.c:474:1: return from a call to EVP_DecryptUpdate
  472.   
  473.       return 1;
  474. > }
  475.   
  476.   int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)

crypto/cms/cms_pwri.c:239:10: Taking true branch
237.           return 0;
238.       /* setup IV by decrypting last two blocks */
239.       if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,
                ^
240.                              in + inlen - 2 * blocklen, blocklen * 2)
241.           /*

crypto/cms/cms_pwri.c:268:2: 
266.       memcpy(out, tmp + 4, *outlen);
267.       rv = 1;
268. >  err:
269.       OPENSSL_clear_free(tmp, inlen);
270.       return rv;

crypto/cms/cms_pwri.c:269:5: 
267.       rv = 1;
268.    err:
269. >     OPENSSL_clear_free(tmp, inlen);
270.       return rv;
271.   

crypto/mem.c:242:1: start of procedure CRYPTO_clear_free()
  240.   }
  241.   
  242. > void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  243.   {
  244.       if (str == NULL)

crypto/mem.c:244:9: Taking false branch
  242.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  243.   {
  244.       if (str == NULL)
                 ^
  245.           return;
  246.       if (num)

crypto/mem.c:246:9: Taking true branch
  244.       if (str == NULL)
  245.           return;
  246.       if (num)
                 ^
  247.           OPENSSL_cleanse(str, num);
  248.       CRYPTO_free(str, file, line);

crypto/mem.c:247:9: Skipping OPENSSL_cleanse(): method has no implementation
  245.           return;
  246.       if (num)
  247.           OPENSSL_cleanse(str, num);
                 ^
  248.       CRYPTO_free(str, file, line);
  249.   }

crypto/mem.c:248:5: 
  246.       if (num)
  247.           OPENSSL_cleanse(str, num);
  248. >     CRYPTO_free(str, file, line);
  249.   }

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

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

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

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

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

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

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

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;
    }
    tmp = OPENSSL_malloc(inlen);
    if (tmp == NULL)
        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    tmp = OPENSSL_malloc(inlen);\n    if (tmp == NULL)\n        return 0;\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    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#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_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n                      const unsigned char *in, int inl)\n{\n    int fix_len;\n    unsigned int b;\n    if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\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 (inl <= 0) {\n        *outl = 0;\n        return inl == 0;\n    }\n    if (ctx->flags & EVP_CIPH_NO_PADDING)\n        return EVP_EncryptUpdate(ctx, out, outl, in, inl);\n    b = ctx->cipher->block_size;\n    OPENSSL_assert(b <= sizeof ctx->final);\n    if (ctx->final_used) {\n        memcpy(out, ctx->final, b);\n        out += b;\n        fix_len = 1;\n    } else\n        fix_len = 0;\n    if (!EVP_EncryptUpdate(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}', '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 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}']