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

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

crypto/mem.c:161:9: Taking false branch
  159.       void *ret = NULL;
  160.   
  161.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                 ^
  162.           return malloc_impl(num, file, line);
  163.   

crypto/mem.c:164:9: Taking false branch
  162.           return malloc_impl(num, file, line);
  163.   
  164.       if (num <= 0)
                 ^
  165.           return NULL;
  166.   

crypto/mem.c:168:5: 
  166.   
  167.       FAILTEST();
  168. >     allow_customize = 0;
  169.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
  170.       if (call_malloc_debug) {

crypto/mem.c:178:5: 
  176.       }
  177.   #else
  178. >     osslargused(file); osslargused(line);
  179.       ret = malloc(num);
  180.   #endif

crypto/mem.c:178:24: 
  176.       }
  177.   #else
  178. >     osslargused(file); osslargused(line);
  179.       ret = malloc(num);
  180.   #endif

crypto/mem.c:179:5: 
  177.   #else
  178.       osslargused(file); osslargused(line);
  179. >     ret = malloc(num);
  180.   #endif
  181.   

crypto/mem.c:182:5: 
  180.   #endif
  181.   
  182. >     return ret;
  183.   }
  184.   

crypto/mem.c:183:1: return from a call to CRYPTO_malloc
  181.   
  182.       return ret;
  183. > }
  184.   
  185.   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:419:1: start of procedure EVP_DecryptUpdate()
  417.   }
  418.   
  419. > int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
  420.                         const unsigned char *in, int inl)
  421.   {

crypto/evp/evp_enc.c:425:9: Taking true branch
  423.       unsigned int b;
  424.   
  425.       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
                 ^
  426.           if (is_partially_overlapping(out, in, inl)) {
  427.               EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);

crypto/evp/evp_enc.c:426:13: 
  424.   
  425.       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
  426. >         if (is_partially_overlapping(out, in, inl)) {
  427.               EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
  428.               return 0;

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:23: Condition is false
    286.        * of conditional branches.]
    287.        */
    288.       int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
                                 ^
    289.                                                   (diff > (0 - (PTRDIFF_T)len)));
    290.       assert(!overlapped);

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

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

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

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

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

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

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

crypto/evp/evp_enc.c:426:13: Taking false branch
  424.   
  425.       if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
  426.           if (is_partially_overlapping(out, in, inl)) {
                     ^
  427.               EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
  428.               return 0;

crypto/evp/evp_enc.c:431:9: Skipping __function_pointer__(): unresolved function pointer
  429.           }
  430.   
  431.           fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
                 ^
  432.           if (fix_len < 0) {
  433.               *outl = 0;

crypto/evp/evp_enc.c:432:13: Taking true branch
  430.   
  431.           fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
  432.           if (fix_len < 0) {
                     ^
  433.               *outl = 0;
  434.               return 0;

crypto/evp/evp_enc.c:433:13: 
  431.           fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
  432.           if (fix_len < 0) {
  433. >             *outl = 0;
  434.               return 0;
  435.           } else

crypto/evp/evp_enc.c:434:13: 
  432.           if (fix_len < 0) {
  433.               *outl = 0;
  434. >             return 0;
  435.           } else
  436.               *outl = fix_len;

crypto/evp/evp_enc.c:482:1: return from a call to EVP_DecryptUpdate
  480.   
  481.       return 1;
  482. > }
  483.   
  484.   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:272:1: start of procedure CRYPTO_clear_free()
  270.   }
  271.   
  272. > void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  273.   {
  274.       if (str == NULL)

crypto/mem.c:274:9: Taking false branch
  272.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  273.   {
  274.       if (str == NULL)
                 ^
  275.           return;
  276.       if (num)

crypto/mem.c:276:9: Taking true branch
  274.       if (str == NULL)
  275.           return;
  276.       if (num)
                 ^
  277.           OPENSSL_cleanse(str, num);
  278.       CRYPTO_free(str, file, line);

crypto/mem.c:277:9: Skipping OPENSSL_cleanse(): method has no implementation
  275.           return;
  276.       if (num)
  277.           OPENSSL_cleanse(str, num);
                 ^
  278.       CRYPTO_free(str, file, line);
  279.   }

crypto/mem.c:278:5: 
  276.       if (num)
  277.           OPENSSL_cleanse(str, num);
  278. >     CRYPTO_free(str, file, line);
  279.   }

crypto/mem.c:252:1: start of procedure CRYPTO_free()
    250.   }
    251.   
    252. > void CRYPTO_free(void *str, const char *file, int line)
    253.   {
    254.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:254:9: Taking true branch
    252.   void CRYPTO_free(void *str, const char *file, int line)
    253.   {
    254.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    255.           free_impl(str, file, line);
    256.           return;

crypto/mem.c:254:30: Taking true branch
    252.   void CRYPTO_free(void *str, const char *file, int line)
    253.   {
    254.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    255.           free_impl(str, file, line);
    256.           return;

crypto/mem.c:255:9: Skipping __function_pointer__(): unresolved function pointer
    253.   {
    254.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    255.           free_impl(str, file, line);
                   ^
    256.           return;
    257.       }

crypto/mem.c:256:9: 
    254.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    255.           free_impl(str, file, line);
    256. >         return;
    257.       }
    258.   

crypto/mem.c:270:1: return from a call to CRYPTO_free
    268.       free(str);
    269.   #endif
    270. > }
    271.   
    272.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

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

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    FAILTEST();\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            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 (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            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_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 overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |\n                                                (diff > (0 - (PTRDIFF_T)len)));\n    assert(!overlapped);\n    return overlapped;\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}']