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


ssl/s3_enc.c:440:1: start of procedure ssl3_generate_master_secret()
438.   }
439.   
440. > int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
441.                                   int len)
442.   {

ssl/s3_enc.c:443:5: 
441.                                   int len)
442.   {
443. >     static const unsigned char *salt[3] = {
444.   #ifndef CHARSET_EBCDIC
445.           (const unsigned char *)"A",

ssl/s3_enc.c:455:5: 
453.       };
454.       unsigned char buf[EVP_MAX_MD_SIZE];
455. >     EVP_MD_CTX *ctx = EVP_MD_CTX_new();
456.       int i, ret = 0;
457.       unsigned int n;

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:98:1: start of procedure CRYPTO_zalloc()
    96.   }
    97.   
    98. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:100:5: 
    98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100. >     void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)

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/mem.c:102:9: Taking true branch
    100.       void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)
                   ^
    103.           memset(ret, 0, num);
    104.       return ret;

crypto/mem.c:103:9: 
    101.   
    102.       if (ret != NULL)
    103. >         memset(ret, 0, num);
    104.       return ret;
    105.   }

crypto/mem.c:104:5: 
    102.       if (ret != NULL)
    103.           memset(ret, 0, num);
    104. >     return ret;
    105.   }
    106.   

crypto/mem.c:105:1: return from a call to CRYPTO_zalloc
    103.           memset(ret, 0, num);
    104.       return ret;
    105. > }
    106.   
    107.   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:456:5: 
454.       unsigned char buf[EVP_MAX_MD_SIZE];
455.       EVP_MD_CTX *ctx = EVP_MD_CTX_new();
456. >     int i, ret = 0;
457.       unsigned int n;
458.   #ifdef OPENSSL_SSL_TRACE_CRYPTO

ssl/s3_enc.c:462:9: Taking false branch
460.   #endif
461.   
462.       if (ctx == NULL) {
               ^
463.           SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_MALLOC_FAILURE);
464.           return 0;

ssl/s3_enc.c:466:10: 
464.           return 0;
465.       }
466. >     for (i = 0; i < 3; i++) {
467.           if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
468.                   || EVP_DigestUpdate(ctx, salt[i],

ssl/s3_enc.c:466:17: Loop condition is true. Entering loop body
464.           return 0;
465.       }
466.       for (i = 0; i < 3; i++) {
                       ^
467.           if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
468.                   || EVP_DigestUpdate(ctx, salt[i],

ssl/s3_enc.c:467:13: Taking true branch
465.       }
466.       for (i = 0; i < 3; i++) {
467.           if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
                   ^
468.                   || EVP_DigestUpdate(ctx, salt[i],
469.                                       strlen((const char *)salt[i])) <= 0

ssl/s3_enc.c:481:13: Skipping ERR_put_error(): empty list of specs
479.                   || EVP_DigestUpdate(ctx, buf, n) <= 0
480.                   || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
481.               SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);
                   ^
482.               ret = 0;
483.               break;

ssl/s3_enc.c:482:13: 
480.                   || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
481.               SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);
482. >             ret = 0;
483.               break;
484.           }

ssl/s3_enc.c:488:5: 
486.           ret += n;
487.       }
488. >     EVP_MD_CTX_free(ctx);
489.   
490.   #ifdef OPENSSL_SSL_TRACE_CRYPTO

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: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/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)

int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
                                int len)
{
    static const unsigned char *salt[3] = {
#ifndef CHARSET_EBCDIC
        (const unsigned char *)"A",
        (const unsigned char *)"BB",
        (const unsigned char *)"CCC",
#else
        (const unsigned char *)"\x41",
        (const unsigned char *)"\x42\x42",
        (const unsigned char *)"\x43\x43\x43",
#endif
    };
    unsigned char buf[EVP_MAX_MD_SIZE];
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
    int i, ret = 0;
    unsigned int n;
#ifdef OPENSSL_SSL_TRACE_CRYPTO
    unsigned char *tmpout = out;
#endif
    if (ctx == NULL) {
        SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    for (i = 0; i < 3; i++) {
        if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
                || EVP_DigestUpdate(ctx, salt[i],
                                    strlen((const char *)salt[i])) <= 0
                || EVP_DigestUpdate(ctx, p, len) <= 0
                || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),
                                    SSL3_RANDOM_SIZE) <= 0
                || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),
                                    SSL3_RANDOM_SIZE) <= 0
                || EVP_DigestFinal_ex(ctx, buf, &n) <= 0
                || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0
                || EVP_DigestUpdate(ctx, p, len) <= 0
                || EVP_DigestUpdate(ctx, buf, n) <= 0
                || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
            SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);
            ret = 0;
            break;
        }
        out += n;
        ret += n;
    }
    EVP_MD_CTX_free(ctx);
#ifdef OPENSSL_SSL_TRACE_CRYPTO
    if (ret > 0 && s->msg_callback) {
        s->msg_callback(2, s->version, TLS1_RT_CRYPTO_PREMASTER,
                        p, len, s, s->msg_callback_arg);
        s->msg_callback(2, s->version, TLS1_RT_CRYPTO_CLIENT_RANDOM,
                        s->s3->client_random, SSL3_RANDOM_SIZE,
                        s, s->msg_callback_arg);
        s->msg_callback(2, s->version, TLS1_RT_CRYPTO_SERVER_RANDOM,
                        s->s3->server_random, SSL3_RANDOM_SIZE,
                        s, s->msg_callback_arg);
        s->msg_callback(2, s->version, TLS1_RT_CRYPTO_MASTER,
                        tmpout, SSL3_MASTER_SECRET_SIZE,
                        s, s->msg_callback_arg);
    }
#endif
    OPENSSL_cleanse(buf, sizeof(buf));
    return (ret);
}
['int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,\n                                int len)\n{\n    static const unsigned char *salt[3] = {\n#ifndef CHARSET_EBCDIC\n        (const unsigned char *)"A",\n        (const unsigned char *)"BB",\n        (const unsigned char *)"CCC",\n#else\n        (const unsigned char *)"\\x41",\n        (const unsigned char *)"\\x42\\x42",\n        (const unsigned char *)"\\x43\\x43\\x43",\n#endif\n    };\n    unsigned char buf[EVP_MAX_MD_SIZE];\n    EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n    int i, ret = 0;\n    unsigned int n;\n#ifdef OPENSSL_SSL_TRACE_CRYPTO\n    unsigned char *tmpout = out;\n#endif\n    if (ctx == NULL) {\n        SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    for (i = 0; i < 3; i++) {\n        if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0\n                || EVP_DigestUpdate(ctx, salt[i],\n                                    strlen((const char *)salt[i])) <= 0\n                || EVP_DigestUpdate(ctx, p, len) <= 0\n                || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),\n                                    SSL3_RANDOM_SIZE) <= 0\n                || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),\n                                    SSL3_RANDOM_SIZE) <= 0\n                || EVP_DigestFinal_ex(ctx, buf, &n) <= 0\n                || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0\n                || EVP_DigestUpdate(ctx, p, len) <= 0\n                || EVP_DigestUpdate(ctx, buf, n) <= 0\n                || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {\n            SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);\n            ret = 0;\n            break;\n        }\n        out += n;\n        ret += n;\n    }\n    EVP_MD_CTX_free(ctx);\n#ifdef OPENSSL_SSL_TRACE_CRYPTO\n    if (ret > 0 && s->msg_callback) {\n        s->msg_callback(2, s->version, TLS1_RT_CRYPTO_PREMASTER,\n                        p, len, s, s->msg_callback_arg);\n        s->msg_callback(2, s->version, TLS1_RT_CRYPTO_CLIENT_RANDOM,\n                        s->s3->client_random, SSL3_RANDOM_SIZE,\n                        s, s->msg_callback_arg);\n        s->msg_callback(2, s->version, TLS1_RT_CRYPTO_SERVER_RANDOM,\n                        s->s3->server_random, SSL3_RANDOM_SIZE,\n                        s, s->msg_callback_arg);\n        s->msg_callback(2, s->version, TLS1_RT_CRYPTO_MASTER,\n                        tmpout, SSL3_MASTER_SECRET_SIZE,\n                        s, s->msg_callback_arg);\n    }\n#endif\n    OPENSSL_cleanse(buf, sizeof(buf));\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    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    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_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}']