ssl/s3_enc.c:99: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 55, column 10 is not reachable after line 99, column 5.
Showing all 66 steps of the trace


ssl/s3_enc.c:42:1: start of procedure ssl3_generate_key_block()
40.   #include <openssl/md5.h>
41.   
42. > static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
43.   {
44.       EVP_MD_CTX *m5;

ssl/s3_enc.c:47:5: 
45.       EVP_MD_CTX *s1;
46.       unsigned char buf[16], smd[SHA_DIGEST_LENGTH];
47. >     unsigned char c = 'A';
48.       unsigned int i, j, k;
49.       int ret = 0;

ssl/s3_enc.c:49:5: 
47.       unsigned char c = 'A';
48.       unsigned int i, j, k;
49. >     int ret = 0;
50.   
51.   #ifdef CHARSET_EBCDIC

ssl/s3_enc.c:54:5: 
52.       c = os_toascii[c];          /* 'A' in ASCII */
53.   #endif
54. >     k = 0;
55.       m5 = EVP_MD_CTX_new();
56.       s1 = EVP_MD_CTX_new();

ssl/s3_enc.c:55:5: 
53.   #endif
54.       k = 0;
55. >     m5 = EVP_MD_CTX_new();
56.       s1 = EVP_MD_CTX_new();
57.       if (m5 == NULL || s1 == NULL) {

crypto/evp/digest.c:44:1: start of procedure EVP_MD_CTX_new()
  42.   }
  43.   
  44. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:46:5: 
  44.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47.   }
  48.   

crypto/mem.c:185:1: start of procedure CRYPTO_zalloc()
    183.   }
    184.   
    185. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    186.   {
    187.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:187:5: 
    185.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    186.   {
    187. >     void *ret = CRYPTO_malloc(num, file, line);
    188.   
    189.       FAILTEST();

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/mem.c:190:9: Taking true branch
    188.   
    189.       FAILTEST();
    190.       if (ret != NULL)
                   ^
    191.           memset(ret, 0, num);
    192.       return ret;

crypto/mem.c:191:9: 
    189.       FAILTEST();
    190.       if (ret != NULL)
    191. >         memset(ret, 0, num);
    192.       return ret;
    193.   }

crypto/mem.c:192:5: 
    190.       if (ret != NULL)
    191.           memset(ret, 0, num);
    192. >     return ret;
    193.   }
    194.   

crypto/mem.c:193:1: return from a call to CRYPTO_zalloc
    191.           memset(ret, 0, num);
    192.       return ret;
    193. > }
    194.   
    195.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:47:1: return from a call to EVP_MD_CTX_new
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47. > }
  48.   
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

ssl/s3_enc.c:56:5: 
54.       k = 0;
55.       m5 = EVP_MD_CTX_new();
56. >     s1 = EVP_MD_CTX_new();
57.       if (m5 == NULL || s1 == NULL) {
58.           SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_MALLOC_FAILURE);

crypto/evp/digest.c:44:1: start of procedure EVP_MD_CTX_new()
  42.   }
  43.   
  44. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:46:5: 
  44.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47.   }
  48.   

crypto/mem.c:185:1: start of procedure CRYPTO_zalloc()
    183.   }
    184.   
    185. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    186.   {
    187.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:187:5: 
    185.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    186.   {
    187. >     void *ret = CRYPTO_malloc(num, file, line);
    188.   
    189.       FAILTEST();

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/mem.c:190:9: Taking true branch
    188.   
    189.       FAILTEST();
    190.       if (ret != NULL)
                   ^
    191.           memset(ret, 0, num);
    192.       return ret;

crypto/mem.c:191:9: 
    189.       FAILTEST();
    190.       if (ret != NULL)
    191. >         memset(ret, 0, num);
    192.       return ret;
    193.   }

crypto/mem.c:192:5: 
    190.       if (ret != NULL)
    191.           memset(ret, 0, num);
    192. >     return ret;
    193.   }
    194.   

crypto/mem.c:193:1: return from a call to CRYPTO_zalloc
    191.           memset(ret, 0, num);
    192.       return ret;
    193. > }
    194.   
    195.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:47:1: return from a call to EVP_MD_CTX_new
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47. > }
  48.   
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

ssl/s3_enc.c:57:9: Taking false branch
55.       m5 = EVP_MD_CTX_new();
56.       s1 = EVP_MD_CTX_new();
57.       if (m5 == NULL || s1 == NULL) {
              ^
58.           SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
59.           goto err;

ssl/s3_enc.c:57:23: Taking false branch
55.       m5 = EVP_MD_CTX_new();
56.       s1 = EVP_MD_CTX_new();
57.       if (m5 == NULL || s1 == NULL) {
                            ^
58.           SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
59.           goto err;

ssl/s3_enc.c:61:5: 
59.           goto err;
60.       }
61. >     EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
62.       for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
63.           k++;

crypto/evp/evp_lib.c:469:1: start of procedure EVP_MD_CTX_set_flags()
  467.   }
  468.   
  469. > void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
  470.   {
  471.       ctx->flags |= flags;

crypto/evp/evp_lib.c:471:5: 
  469.   void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
  470.   {
  471. >     ctx->flags |= flags;
  472.   }
  473.   

crypto/evp/evp_lib.c:472:1: return from a call to EVP_MD_CTX_set_flags
  470.   {
  471.       ctx->flags |= flags;
  472. > }
  473.   
  474.   void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags)

ssl/s3_enc.c:62:10: 
60.       }
61.       EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
62. >     for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
63.           k++;
64.           if (k > sizeof buf) {

ssl/s3_enc.c:62:17: Loop condition is false. Leaving loop
60.       }
61.       EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
62.       for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
                      ^
63.           k++;
64.           if (k > sizeof buf) {

ssl/s3_enc.c:96:5: Skipping OPENSSL_cleanse(): method has no implementation
94.           km += MD5_DIGEST_LENGTH;
95.       }
96.       OPENSSL_cleanse(smd, sizeof(smd));
          ^
97.       ret = 1;
98.    err:

ssl/s3_enc.c:97:5: 
95.       }
96.       OPENSSL_cleanse(smd, sizeof(smd));
97. >     ret = 1;
98.    err:
99.       EVP_MD_CTX_free(m5);

ssl/s3_enc.c:98:2: 
96.       OPENSSL_cleanse(smd, sizeof(smd));
97.       ret = 1;
98. >  err:
99.       EVP_MD_CTX_free(m5);
100.       EVP_MD_CTX_free(s1);

ssl/s3_enc.c:99:5: 
97.       ret = 1;
98.    err:
99. >     EVP_MD_CTX_free(m5);
100.       EVP_MD_CTX_free(s1);
101.       return ret;

crypto/evp/digest.c:49:1: start of procedure EVP_MD_CTX_free()
  47.   }
  48.   
  49. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:51:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
            ^
  52.       OPENSSL_free(ctx);
  53.   }

crypto/evp/digest.c:52:5: 
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
  52. >     OPENSSL_free(ctx);
  53.   }
  54.   

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/evp/digest.c:53:1: return from a call to EVP_MD_CTX_free
  51.       EVP_MD_CTX_reset(ctx);
  52.       OPENSSL_free(ctx);
  53. > }
  54.   
  55.   int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)

static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
{
    EVP_MD_CTX *m5;
    EVP_MD_CTX *s1;
    unsigned char buf[16], smd[SHA_DIGEST_LENGTH];
    unsigned char c = 'A';
    unsigned int i, j, k;
    int ret = 0;
#ifdef CHARSET_EBCDIC
    c = os_toascii[c];
#endif
    k = 0;
    m5 = EVP_MD_CTX_new();
    s1 = EVP_MD_CTX_new();
    if (m5 == NULL || s1 == NULL) {
        SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
    for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
        k++;
        if (k > sizeof buf) {
            SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_INTERNAL_ERROR);
            return 0;
        }
        for (j = 0; j < k; j++)
            buf[j] = c;
        c++;
        if (!EVP_DigestInit_ex(s1, EVP_sha1(), NULL)
            || !EVP_DigestUpdate(s1, buf, k)
            || !EVP_DigestUpdate(s1, s->session->master_key,
                                 s->session->master_key_length)
            || !EVP_DigestUpdate(s1, s->s3->server_random, SSL3_RANDOM_SIZE)
            || !EVP_DigestUpdate(s1, s->s3->client_random, SSL3_RANDOM_SIZE)
            || !EVP_DigestFinal_ex(s1, smd, NULL)
            || !EVP_DigestInit_ex(m5, EVP_md5(), NULL)
            || !EVP_DigestUpdate(m5, s->session->master_key,
                                 s->session->master_key_length)
            || !EVP_DigestUpdate(m5, smd, SHA_DIGEST_LENGTH))
            goto err;
        if ((int)(i + MD5_DIGEST_LENGTH) > num) {
            if (!EVP_DigestFinal_ex(m5, smd, NULL))
                goto err;
            memcpy(km, smd, (num - i));
        } else {
            if (!EVP_DigestFinal_ex(m5, km, NULL))
                goto err;
        }
        km += MD5_DIGEST_LENGTH;
    }
    OPENSSL_cleanse(smd, sizeof(smd));
    ret = 1;
 err:
    EVP_MD_CTX_free(m5);
    EVP_MD_CTX_free(s1);
    return ret;
}
["static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)\n{\n    EVP_MD_CTX *m5;\n    EVP_MD_CTX *s1;\n    unsigned char buf[16], smd[SHA_DIGEST_LENGTH];\n    unsigned char c = 'A';\n    unsigned int i, j, k;\n    int ret = 0;\n#ifdef CHARSET_EBCDIC\n    c = os_toascii[c];\n#endif\n    k = 0;\n    m5 = EVP_MD_CTX_new();\n    s1 = EVP_MD_CTX_new();\n    if (m5 == NULL || s1 == NULL) {\n        SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);\n    for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {\n        k++;\n        if (k > sizeof buf) {\n            SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        for (j = 0; j < k; j++)\n            buf[j] = c;\n        c++;\n        if (!EVP_DigestInit_ex(s1, EVP_sha1(), NULL)\n            || !EVP_DigestUpdate(s1, buf, k)\n            || !EVP_DigestUpdate(s1, s->session->master_key,\n                                 s->session->master_key_length)\n            || !EVP_DigestUpdate(s1, s->s3->server_random, SSL3_RANDOM_SIZE)\n            || !EVP_DigestUpdate(s1, s->s3->client_random, SSL3_RANDOM_SIZE)\n            || !EVP_DigestFinal_ex(s1, smd, NULL)\n            || !EVP_DigestInit_ex(m5, EVP_md5(), NULL)\n            || !EVP_DigestUpdate(m5, s->session->master_key,\n                                 s->session->master_key_length)\n            || !EVP_DigestUpdate(m5, smd, SHA_DIGEST_LENGTH))\n            goto err;\n        if ((int)(i + MD5_DIGEST_LENGTH) > num) {\n            if (!EVP_DigestFinal_ex(m5, smd, NULL))\n                goto err;\n            memcpy(km, smd, (num - i));\n        } else {\n            if (!EVP_DigestFinal_ex(m5, km, NULL))\n                goto err;\n        }\n        km += MD5_DIGEST_LENGTH;\n    }\n    OPENSSL_cleanse(smd, sizeof(smd));\n    ret = 1;\n err:\n    EVP_MD_CTX_free(m5);\n    EVP_MD_CTX_free(s1);\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    FAILTEST();\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 (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}', 'void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)\n{\n    ctx->flags |= flags;\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n    EVP_MD_CTX_reset(ctx);\n    OPENSSL_free(ctx);\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}']