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


ssl/s3_enc.c:17:1: start of procedure ssl3_generate_key_block()
15.   #include "internal/cryptlib.h"
16.   
17. > static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
18.   {
19.       EVP_MD_CTX *m5;

ssl/s3_enc.c:22:5: 
20.       EVP_MD_CTX *s1;
21.       unsigned char buf[16], smd[SHA_DIGEST_LENGTH];
22. >     unsigned char c = 'A';
23.       unsigned int i, j, k;
24.       int ret = 0;

ssl/s3_enc.c:24:5: 
22.       unsigned char c = 'A';
23.       unsigned int i, j, k;
24. >     int ret = 0;
25.   
26.   #ifdef CHARSET_EBCDIC

ssl/s3_enc.c:29:5: 
27.       c = os_toascii[c];          /* 'A' in ASCII */
28.   #endif
29. >     k = 0;
30.       m5 = EVP_MD_CTX_new();
31.       s1 = EVP_MD_CTX_new();

ssl/s3_enc.c:30:5: 
28.   #endif
29.       k = 0;
30. >     m5 = EVP_MD_CTX_new();
31.       s1 = EVP_MD_CTX_new();
32.       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:221:1: start of procedure CRYPTO_zalloc()
    219.   }
    220.   
    221. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    222.   {
    223.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:223:5: 
    221.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    222.   {
    223. >     void *ret = CRYPTO_malloc(num, file, line);
    224.   
    225.       FAILTEST();

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:5: 
      202.   
      203.       FAILTEST();
      204. >     allow_customize = 0;
      205.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      206.       if (call_malloc_debug) {

crypto/mem.c:214:5: 
      212.       }
      213.   #else
      214. >     (void)(file); (void)(line);
      215.       ret = malloc(num);
      216.   #endif

crypto/mem.c:214:19: 
      212.       }
      213.   #else
      214. >     (void)(file); (void)(line);
      215.       ret = malloc(num);
      216.   #endif

crypto/mem.c:215:5: 
      213.   #else
      214.       (void)(file); (void)(line);
      215. >     ret = malloc(num);
      216.   #endif
      217.   

crypto/mem.c:218:5: 
      216.   #endif
      217.   
      218. >     return ret;
      219.   }
      220.   

crypto/mem.c:219:1: return from a call to CRYPTO_malloc
      217.   
      218.       return ret;
      219. > }
      220.   
      221.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:226:9: Taking true branch
    224.   
    225.       FAILTEST();
    226.       if (ret != NULL)
                   ^
    227.           memset(ret, 0, num);
    228.       return ret;

crypto/mem.c:227:9: 
    225.       FAILTEST();
    226.       if (ret != NULL)
    227. >         memset(ret, 0, num);
    228.       return ret;
    229.   }

crypto/mem.c:228:5: 
    226.       if (ret != NULL)
    227.           memset(ret, 0, num);
    228. >     return ret;
    229.   }
    230.   

crypto/mem.c:229:1: return from a call to CRYPTO_zalloc
    227.           memset(ret, 0, num);
    228.       return ret;
    229. > }
    230.   
    231.   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:31:5: 
29.       k = 0;
30.       m5 = EVP_MD_CTX_new();
31. >     s1 = EVP_MD_CTX_new();
32.       if (m5 == NULL || s1 == NULL) {
33.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,

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:221:1: start of procedure CRYPTO_zalloc()
    219.   }
    220.   
    221. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    222.   {
    223.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:223:5: 
    221.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    222.   {
    223. >     void *ret = CRYPTO_malloc(num, file, line);
    224.   
    225.       FAILTEST();

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:5: 
      202.   
      203.       FAILTEST();
      204. >     allow_customize = 0;
      205.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      206.       if (call_malloc_debug) {

crypto/mem.c:214:5: 
      212.       }
      213.   #else
      214. >     (void)(file); (void)(line);
      215.       ret = malloc(num);
      216.   #endif

crypto/mem.c:214:19: 
      212.       }
      213.   #else
      214. >     (void)(file); (void)(line);
      215.       ret = malloc(num);
      216.   #endif

crypto/mem.c:215:5: 
      213.   #else
      214.       (void)(file); (void)(line);
      215. >     ret = malloc(num);
      216.   #endif
      217.   

crypto/mem.c:218:5: 
      216.   #endif
      217.   
      218. >     return ret;
      219.   }
      220.   

crypto/mem.c:219:1: return from a call to CRYPTO_malloc
      217.   
      218.       return ret;
      219. > }
      220.   
      221.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:226:9: Taking true branch
    224.   
    225.       FAILTEST();
    226.       if (ret != NULL)
                   ^
    227.           memset(ret, 0, num);
    228.       return ret;

crypto/mem.c:227:9: 
    225.       FAILTEST();
    226.       if (ret != NULL)
    227. >         memset(ret, 0, num);
    228.       return ret;
    229.   }

crypto/mem.c:228:5: 
    226.       if (ret != NULL)
    227.           memset(ret, 0, num);
    228. >     return ret;
    229.   }
    230.   

crypto/mem.c:229:1: return from a call to CRYPTO_zalloc
    227.           memset(ret, 0, num);
    228.       return ret;
    229. > }
    230.   
    231.   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:32:9: Taking false branch
30.       m5 = EVP_MD_CTX_new();
31.       s1 = EVP_MD_CTX_new();
32.       if (m5 == NULL || s1 == NULL) {
              ^
33.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,
34.                    ERR_R_MALLOC_FAILURE);

ssl/s3_enc.c:32:23: Taking false branch
30.       m5 = EVP_MD_CTX_new();
31.       s1 = EVP_MD_CTX_new();
32.       if (m5 == NULL || s1 == NULL) {
                            ^
33.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,
34.                    ERR_R_MALLOC_FAILURE);

ssl/s3_enc.c:37:5: 
35.           goto err;
36.       }
37. >     EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
38.       for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
39.           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:38:10: 
36.       }
37.       EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
38. >     for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
39.           k++;
40.           if (k > sizeof(buf)) {

ssl/s3_enc.c:38:17: Loop condition is true. Entering loop body
36.       }
37.       EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
38.       for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
                      ^
39.           k++;
40.           if (k > sizeof(buf)) {

ssl/s3_enc.c:39:9: 
37.       EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
38.       for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
39. >         k++;
40.           if (k > sizeof(buf)) {
41.               /* bug: 'buf' is too small for this ciphersuite */

ssl/s3_enc.c:40:13: Taking false branch
38.       for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
39.           k++;
40.           if (k > sizeof(buf)) {
                  ^
41.               /* bug: 'buf' is too small for this ciphersuite */
42.               SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,

ssl/s3_enc.c:47:14: 
45.           }
46.   
47. >         for (j = 0; j < k; j++)
48.               buf[j] = c;
49.           c++;

ssl/s3_enc.c:47:21: Loop condition is true. Entering loop body
45.           }
46.   
47.           for (j = 0; j < k; j++)
                          ^
48.               buf[j] = c;
49.           c++;

ssl/s3_enc.c:48:13: 
46.   
47.           for (j = 0; j < k; j++)
48. >             buf[j] = c;
49.           c++;
50.           if (!EVP_DigestInit_ex(s1, EVP_sha1(), NULL)

ssl/s3_enc.c:47:28: 
45.           }
46.   
47. >         for (j = 0; j < k; j++)
48.               buf[j] = c;
49.           c++;

ssl/s3_enc.c:47:21: Loop condition is false. Leaving loop
45.           }
46.   
47.           for (j = 0; j < k; j++)
                          ^
48.               buf[j] = c;
49.           c++;

ssl/s3_enc.c:49:9: 
47.           for (j = 0; j < k; j++)
48.               buf[j] = c;
49. >         c++;
50.           if (!EVP_DigestInit_ex(s1, EVP_sha1(), NULL)
51.               || !EVP_DigestUpdate(s1, buf, k)

ssl/s3_enc.c:50:14: 
48.               buf[j] = c;
49.           c++;
50. >         if (!EVP_DigestInit_ex(s1, EVP_sha1(), NULL)
51.               || !EVP_DigestUpdate(s1, buf, k)
52.               || !EVP_DigestUpdate(s1, s->session->master_key,

crypto/evp/m_sha1.c:109:1: start of procedure EVP_sha1()
  107.   };
  108.   
  109. > const EVP_MD *EVP_sha1(void)
  110.   {
  111.       return &sha1_md;

crypto/evp/m_sha1.c:111:5: 
  109.   const EVP_MD *EVP_sha1(void)
  110.   {
  111. >     return &sha1_md;
  112.   }
  113.   

crypto/evp/m_sha1.c:112:1: return from a call to EVP_sha1
  110.   {
  111.       return &sha1_md;
  112. > }
  113.   
  114.   static int init224(EVP_MD_CTX *ctx)

ssl/s3_enc.c:50:14: Taking true branch
48.               buf[j] = c;
49.           c++;
50.           if (!EVP_DigestInit_ex(s1, EVP_sha1(), NULL)
                   ^
51.               || !EVP_DigestUpdate(s1, buf, k)
52.               || !EVP_DigestUpdate(s1, s->session->master_key,

ssl/s3_enc.c:61:13: 
59.                                    s->session->master_key_length)
60.               || !EVP_DigestUpdate(m5, smd, SHA_DIGEST_LENGTH)) {
61. >             SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,
62.                        ERR_R_INTERNAL_ERROR);
63.               goto err;

test/tls13secretstest.c:210:1: start of procedure ossl_statem_fatal()
  208.   }
  209.   
  210. > void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,
  211.                              int line)
  212.   {

test/tls13secretstest.c:213:1: return from a call to ossl_statem_fatal
  211.                              int line)
  212.   {
  213. > }
  214.   
  215.   int ossl_statem_export_allowed(SSL *s)

ssl/s3_enc.c:84:2: 
82.       OPENSSL_cleanse(smd, sizeof(smd));
83.       ret = 1;
84. >  err:
85.       EVP_MD_CTX_free(m5);
86.       EVP_MD_CTX_free(s1);

ssl/s3_enc.c:85:5: 
83.       ret = 1;
84.    err:
85. >     EVP_MD_CTX_free(m5);
86.       EVP_MD_CTX_free(s1);
87.       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:289:1: start of procedure CRYPTO_free()
    287.   }
    288.   
    289. > void CRYPTO_free(void *str, const char *file, int line)
    290.   {
    291.       INCREMENT(free_count);

crypto/mem.c:292:9: Taking false branch
    290.   {
    291.       INCREMENT(free_count);
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    293.           free_impl(str, file, line);
    294.           return;

crypto/mem.c:306:5: 
    304.       }
    305.   #else
    306. >     free(str);
    307.   #endif
    308.   }

crypto/mem.c:308:1: return from a call to CRYPTO_free
    306.       free(str);
    307.   #endif
    308. > }
    309.   
    310.   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)

ssl/s3_enc.c:86:5: 
84.    err:
85.       EVP_MD_CTX_free(m5);
86. >     EVP_MD_CTX_free(s1);
87.       return ret;
88.   }

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:289:1: start of procedure CRYPTO_free()
    287.   }
    288.   
    289. > void CRYPTO_free(void *str, const char *file, int line)
    290.   {
    291.       INCREMENT(free_count);

crypto/mem.c:292:9: Taking true branch
    290.   {
    291.       INCREMENT(free_count);
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    293.           free_impl(str, file, line);
    294.           return;

crypto/mem.c:292:30: Taking true branch
    290.   {
    291.       INCREMENT(free_count);
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    293.           free_impl(str, file, line);
    294.           return;

crypto/mem.c:293:9: Skipping __function_pointer__(): unresolved function pointer
    291.       INCREMENT(free_count);
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    293.           free_impl(str, file, line);
                   ^
    294.           return;
    295.       }

crypto/mem.c:294:9: 
    292.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    293.           free_impl(str, file, line);
    294. >         return;
    295.       }
    296.   

crypto/mem.c:308:1: return from a call to CRYPTO_free
    306.       free(str);
    307.   #endif
    308. > }
    309.   
    310.   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) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, 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)) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,
                     ERR_R_INTERNAL_ERROR);
            goto err;
        }
        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)) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,
                     ERR_R_INTERNAL_ERROR);
            goto err;
        }
        if ((int)(i + MD5_DIGEST_LENGTH) > num) {
            if (!EVP_DigestFinal_ex(m5, smd, NULL)) {
                SSLfatal(s, SSL_AD_INTERNAL_ERROR,
                         SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_INTERNAL_ERROR);
                goto err;
            }
            memcpy(km, smd, (num - i));
        } else {
            if (!EVP_DigestFinal_ex(m5, km, NULL)) {
                SSLfatal(s, SSL_AD_INTERNAL_ERROR,
                         SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_INTERNAL_ERROR);
                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        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,\n                 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            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,\n                     ERR_R_INTERNAL_ERROR);\n            goto err;\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            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_KEY_BLOCK,\n                     ERR_R_INTERNAL_ERROR);\n            goto err;\n        }\n        if ((int)(i + MD5_DIGEST_LENGTH) > num) {\n            if (!EVP_DigestFinal_ex(m5, smd, NULL)) {\n                SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n                         SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_INTERNAL_ERROR);\n                goto err;\n            }\n            memcpy(km, smd, (num - i));\n        } else {\n            if (!EVP_DigestFinal_ex(m5, km, NULL)) {\n                SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n                         SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_INTERNAL_ERROR);\n                goto err;\n            }\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    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    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    (void)(file); (void)(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}', 'const EVP_MD *EVP_sha1(void)\n{\n    return &sha1_md;\n}', 'void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,\n                           int line)\n{\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    INCREMENT(free_count);\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}']