crypto/cms/cms_pwri.c:225: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_malloc()` at line 191, column 11 is not reachable after line 225, column 5.
Showing all 55 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:170:1: start of procedure EVP_CIPHER_CTX_block_size()
  168.   }
  169.   
  170. > int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
  171.   {
  172.       return ctx->cipher->block_size;

crypto/evp/evp_lib.c:172:5: 
  170.   int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
  171.   {
  172. >     return ctx->cipher->block_size;
  173.   }
  174.   

crypto/evp/evp_lib.c:173:1: return from a call to EVP_CIPHER_CTX_block_size
  171.   {
  172.       return ctx->cipher->block_size;
  173. > }
  174.   
  175.   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:5: 
189.           return 0;
190.       }
191. >     tmp = OPENSSL_malloc(inlen);
192.       if (tmp == NULL)
193.           return 0;

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/cms/cms_pwri.c:192:9: Taking false branch
190.       }
191.       tmp = OPENSSL_malloc(inlen);
192.       if (tmp == NULL)
               ^
193.           return 0;
194.       /* setup IV by decrypting last two blocks */

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

crypto/evp/evp_enc.c:413:1: start of procedure EVP_DecryptUpdate()
  411.   }
  412.   
  413. > int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
  414.                         const unsigned char *in, int inl)
  415.   {

crypto/evp/evp_enc.c:419:9: Taking true branch
  417.       unsigned int b;
  418.   
  419.       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
                 ^
  420.           if (is_partially_overlapping(out, in, inl))
  421.               return 0;

crypto/evp/evp_enc.c:420:13: 
  418.   
  419.       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
  420. >         if (is_partially_overlapping(out, in, inl))
  421.               return 0;
  422.   

crypto/evp/evp_enc.c:279:1: start of procedure is_partially_overlapping()
    277.   #endif
    278.   
    279. > static int is_partially_overlapping(const void *ptr1, const void *ptr2,
    280.                                       int len)
    281.   {

crypto/evp/evp_enc.c:282:5: 
    280.                                       int len)
    281.   {
    282. >     PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;
    283.       /*
    284.        * Check for partially overlapping buffers. [Binary logical

crypto/evp/evp_enc.c:288:22: Condition is false
    286.        * of conditional branches.]
    287.        */
    288.       int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
                                ^
    289.                                                  (diff > (0 - (PTRDIFF_T)len)));
    290.       assert(!condition);

crypto/evp/evp_enc.c:288:34: Condition is true
    286.        * of conditional branches.]
    287.        */
    288.       int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
                                            ^
    289.                                                  (diff > (0 - (PTRDIFF_T)len)));
    290.       assert(!condition);

crypto/evp/evp_enc.c:288:49: Condition is true
    286.        * of conditional branches.]
    287.        */
    288.       int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
                                                           ^
    289.                                                  (diff > (0 - (PTRDIFF_T)len)));
    290.       assert(!condition);

crypto/evp/evp_enc.c:289:49: Condition is true
    287.        */
    288.       int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
    289.                                                  (diff > (0 - (PTRDIFF_T)len)));
                                                           ^
    290.       assert(!condition);
    291.       return condition;

crypto/evp/evp_enc.c:288:5: 
    286.        * of conditional branches.]
    287.        */
    288. >     int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
    289.                                                  (diff > (0 - (PTRDIFF_T)len)));
    290.       assert(!condition);

crypto/evp/evp_enc.c:290:5: 
    288.       int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
    289.                                                  (diff > (0 - (PTRDIFF_T)len)));
    290. >     assert(!condition);
    291.       return condition;
    292.   }

crypto/evp/evp_enc.c:291:5: 
    289.                                                  (diff > (0 - (PTRDIFF_T)len)));
    290.       assert(!condition);
    291. >     return condition;
    292.   }
    293.   

crypto/evp/evp_enc.c:292:1: return from a call to is_partially_overlapping
    290.       assert(!condition);
    291.       return condition;
    292. > }
    293.   
    294.   int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,

crypto/evp/evp_enc.c:420:13: Taking false branch
  418.   
  419.       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
  420.           if (is_partially_overlapping(out, in, inl))
                     ^
  421.               return 0;
  422.   

crypto/evp/evp_enc.c:423:9: Skipping __function_pointer__(): unresolved function pointer
  421.               return 0;
  422.   
  423.           fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
                 ^
  424.           if (fix_len < 0) {
  425.               *outl = 0;

crypto/evp/evp_enc.c:424:13: Taking true branch
  422.   
  423.           fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
  424.           if (fix_len < 0) {
                     ^
  425.               *outl = 0;
  426.               return 0;

crypto/evp/evp_enc.c:425:13: 
  423.           fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
  424.           if (fix_len < 0) {
  425. >             *outl = 0;
  426.               return 0;
  427.           } else

crypto/evp/evp_enc.c:426:13: 
  424.           if (fix_len < 0) {
  425.               *outl = 0;
  426. >             return 0;
  427.           } else
  428.               *outl = fix_len;

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

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

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

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

crypto/mem.c:183:1: start of procedure CRYPTO_clear_free()
  181.   }
  182.   
  183. > void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  184.   {
  185.       if (str == NULL)

crypto/mem.c:185:9: Taking false branch
  183.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  184.   {
  185.       if (str == NULL)
                 ^
  186.           return;
  187.       if (num)

crypto/mem.c:187:9: Taking true branch
  185.       if (str == NULL)
  186.           return;
  187.       if (num)
                 ^
  188.           OPENSSL_cleanse(str, num);
  189.       CRYPTO_free(str, file, line);

crypto/mem.c:188:9: Skipping OPENSSL_cleanse(): method has no implementation
  186.           return;
  187.       if (num)
  188.           OPENSSL_cleanse(str, num);
                 ^
  189.       CRYPTO_free(str, file, line);
  190.   }

crypto/mem.c:189:5: 
  187.       if (num)
  188.           OPENSSL_cleanse(str, num);
  189. >     CRYPTO_free(str, file, line);
  190.   }

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/mem.c:190:1: return from a call to CRYPTO_clear_free
  188.           OPENSSL_cleanse(str, num);
  189.       CRYPTO_free(str, file, line);
  190. > }

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    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        if (is_partially_overlapping(out, in, inl))\n            return 0;\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        if (((PTRDIFF_T)out == (PTRDIFF_T)in)\n            || is_partially_overlapping(out, in, b))\n            return 0;\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}', 'static int is_partially_overlapping(const void *ptr1, const void *ptr2,\n                                    int len)\n{\n    PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;\n    int condition = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |\n                                               (diff > (0 - (PTRDIFF_T)len)));\n    assert(!condition);\n    return condition;\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}']