ssl/statem/statem_clnt.c:2171: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_malloc()` at line 2123, column 11 is not reachable after line 2171, column 5.
Showing all 58 steps of the trace


ssl/statem/statem_clnt.c:2098:1: start of procedure tls_construct_cke_rsa()
2096.   }
2097.   
2098. > static int tls_construct_cke_rsa(SSL *s, unsigned char **p, int *len, int *al)
2099.   {
2100.   #ifndef OPENSSL_NO_RSA

ssl/statem/statem_clnt.c:2102:5: 
2100.   #ifndef OPENSSL_NO_RSA
2101.       unsigned char *q;
2102. >     EVP_PKEY *pkey = NULL;
2103.       EVP_PKEY_CTX *pctx = NULL;
2104.       size_t enclen;

ssl/statem/statem_clnt.c:2103:5: 
2101.       unsigned char *q;
2102.       EVP_PKEY *pkey = NULL;
2103. >     EVP_PKEY_CTX *pctx = NULL;
2104.       size_t enclen;
2105.       unsigned char *pms = NULL;

ssl/statem/statem_clnt.c:2105:5: 
2103.       EVP_PKEY_CTX *pctx = NULL;
2104.       size_t enclen;
2105. >     unsigned char *pms = NULL;
2106.       size_t pmslen = 0;
2107.   

ssl/statem/statem_clnt.c:2106:5: 
2104.       size_t enclen;
2105.       unsigned char *pms = NULL;
2106. >     size_t pmslen = 0;
2107.   
2108.       if (s->session->peer == NULL) {

ssl/statem/statem_clnt.c:2108:9: Taking false branch
2106.       size_t pmslen = 0;
2107.   
2108.       if (s->session->peer == NULL) {
                ^
2109.           /*
2110.            * We should always have a server certificate with SSL_kRSA.

ssl/statem/statem_clnt.c:2116:5: 
2114.       }
2115.   
2116. >     pkey = X509_get0_pubkey(s->session->peer);
2117.       if (EVP_PKEY_get0_RSA(pkey) == NULL) {
2118.           SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);

crypto/x509/x509_cmp.c:260:1: start of procedure X509_get0_pubkey()
  258.   }
  259.   
  260. > EVP_PKEY *X509_get0_pubkey(X509 *x)
  261.   {
  262.       if (x == NULL)

crypto/x509/x509_cmp.c:262:9: Taking false branch
  260.   EVP_PKEY *X509_get0_pubkey(X509 *x)
  261.   {
  262.       if (x == NULL)
                 ^
  263.           return NULL;
  264.       return X509_PUBKEY_get0(x->cert_info.key);

crypto/x509/x509_cmp.c:264:5: Skipping X509_PUBKEY_get0(): empty list of specs
  262.       if (x == NULL)
  263.           return NULL;
  264.       return X509_PUBKEY_get0(x->cert_info.key);
             ^
  265.   }
  266.   

crypto/x509/x509_cmp.c:265:1: return from a call to X509_get0_pubkey
  263.           return NULL;
  264.       return X509_PUBKEY_get0(x->cert_info.key);
  265. > }
  266.   
  267.   EVP_PKEY *X509_get_pubkey(X509 *x)

ssl/statem/statem_clnt.c:2117:9: 
2115.   
2116.       pkey = X509_get0_pubkey(s->session->peer);
2117. >     if (EVP_PKEY_get0_RSA(pkey) == NULL) {
2118.           SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
2119.           return 0;

crypto/evp/p_lib.c:261:1: start of procedure EVP_PKEY_get0_RSA()
  259.   }
  260.   
  261. > RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
  262.   {
  263.       if (pkey->type != EVP_PKEY_RSA) {

crypto/evp/p_lib.c:263:9: Taking false branch
  261.   RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
  262.   {
  263.       if (pkey->type != EVP_PKEY_RSA) {
                 ^
  264.           EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
  265.           return NULL;

crypto/evp/p_lib.c:267:5: 
  265.           return NULL;
  266.       }
  267. >     return pkey->pkey.rsa;
  268.   }
  269.   

crypto/evp/p_lib.c:268:1: return from a call to EVP_PKEY_get0_RSA
  266.       }
  267.       return pkey->pkey.rsa;
  268. > }
  269.   
  270.   RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)

ssl/statem/statem_clnt.c:2117:9: Taking false branch
2115.   
2116.       pkey = X509_get0_pubkey(s->session->peer);
2117.       if (EVP_PKEY_get0_RSA(pkey) == NULL) {
                ^
2118.           SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
2119.           return 0;

ssl/statem/statem_clnt.c:2122:5: 
2120.       }
2121.   
2122. >     pmslen = SSL_MAX_MASTER_KEY_LENGTH;
2123.       pms = OPENSSL_malloc(pmslen);
2124.       if (pms == NULL) {

ssl/statem/statem_clnt.c:2123:5: 
2121.   
2122.       pmslen = SSL_MAX_MASTER_KEY_LENGTH;
2123. >     pms = OPENSSL_malloc(pmslen);
2124.       if (pms == NULL) {
2125.           SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);

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)

ssl/statem/statem_clnt.c:2124:9: Taking false branch
2122.       pmslen = SSL_MAX_MASTER_KEY_LENGTH;
2123.       pms = OPENSSL_malloc(pmslen);
2124.       if (pms == NULL) {
                ^
2125.           SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);
2126.           *al = SSL_AD_INTERNAL_ERROR;

ssl/statem/statem_clnt.c:2130:5: 
2128.       }
2129.   
2130. >     pms[0] = s->client_version >> 8;
2131.       pms[1] = s->client_version & 0xff;
2132.       if (RAND_bytes(pms + 2, pmslen - 2) <= 0) {

ssl/statem/statem_clnt.c:2131:5: 
2129.   
2130.       pms[0] = s->client_version >> 8;
2131. >     pms[1] = s->client_version & 0xff;
2132.       if (RAND_bytes(pms + 2, pmslen - 2) <= 0) {
2133.           goto err;

ssl/statem/statem_clnt.c:2132:9: 
2130.       pms[0] = s->client_version >> 8;
2131.       pms[1] = s->client_version & 0xff;
2132. >     if (RAND_bytes(pms + 2, pmslen - 2) <= 0) {
2133.           goto err;
2134.       }

crypto/rand/rand_lib.c:102:1: start of procedure RAND_bytes()
  100.   }
  101.   
  102. > int RAND_bytes(unsigned char *buf, int num)
  103.   {
  104.       const RAND_METHOD *meth = RAND_get_rand_method();

crypto/rand/rand_lib.c:104:5: 
  102.   int RAND_bytes(unsigned char *buf, int num)
  103.   {
  104. >     const RAND_METHOD *meth = RAND_get_rand_method();
  105.       if (meth && meth->bytes)
  106.           return meth->bytes(buf, num);

crypto/rand/rand_lib.c:39:1: start of procedure RAND_get_rand_method()
    37.   }
    38.   
    39. > const RAND_METHOD *RAND_get_rand_method(void)
    40.   {
    41.       if (!default_RAND_meth) {

crypto/rand/rand_lib.c:41:10: Taking false branch
    39.   const RAND_METHOD *RAND_get_rand_method(void)
    40.   {
    41.       if (!default_RAND_meth) {
                   ^
    42.   #ifndef OPENSSL_NO_ENGINE
    43.           ENGINE *e = ENGINE_get_default_RAND();

crypto/rand/rand_lib.c:57:5: 
    55.               default_RAND_meth = RAND_OpenSSL();
    56.       }
    57. >     return default_RAND_meth;
    58.   }
    59.   

crypto/rand/rand_lib.c:58:1: return from a call to RAND_get_rand_method
    56.       }
    57.       return default_RAND_meth;
    58. > }
    59.   
    60.   #ifndef OPENSSL_NO_ENGINE

crypto/rand/rand_lib.c:105:9: Taking true branch
  103.   {
  104.       const RAND_METHOD *meth = RAND_get_rand_method();
  105.       if (meth && meth->bytes)
                 ^
  106.           return meth->bytes(buf, num);
  107.       return (-1);

crypto/rand/rand_lib.c:105:17: Taking false branch
  103.   {
  104.       const RAND_METHOD *meth = RAND_get_rand_method();
  105.       if (meth && meth->bytes)
                         ^
  106.           return meth->bytes(buf, num);
  107.       return (-1);

crypto/rand/rand_lib.c:107:5: 
  105.       if (meth && meth->bytes)
  106.           return meth->bytes(buf, num);
  107. >     return (-1);
  108.   }
  109.   

crypto/rand/rand_lib.c:108:1: return from a call to RAND_bytes
  106.           return meth->bytes(buf, num);
  107.       return (-1);
  108. > }
  109.   
  110.   #if OPENSSL_API_COMPAT < 0x10100000L

ssl/statem/statem_clnt.c:2132:9: Taking true branch
2130.       pms[0] = s->client_version >> 8;
2131.       pms[1] = s->client_version & 0xff;
2132.       if (RAND_bytes(pms + 2, pmslen - 2) <= 0) {
                ^
2133.           goto err;
2134.       }

ssl/statem/statem_clnt.c:2170:2: 
2168.   
2169.       return 1;
2170. >  err:
2171.       OPENSSL_clear_free(pms, pmslen);
2172.       EVP_PKEY_CTX_free(pctx);

ssl/statem/statem_clnt.c:2171:5: 
2169.       return 1;
2170.    err:
2171. >     OPENSSL_clear_free(pms, pmslen);
2172.       EVP_PKEY_CTX_free(pctx);
2173.   

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 tls_construct_cke_rsa(SSL *s, unsigned char **p, int *len, int *al)
{
#ifndef OPENSSL_NO_RSA
    unsigned char *q;
    EVP_PKEY *pkey = NULL;
    EVP_PKEY_CTX *pctx = NULL;
    size_t enclen;
    unsigned char *pms = NULL;
    size_t pmslen = 0;
    if (s->session->peer == NULL) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
        return 0;
    }
    pkey = X509_get0_pubkey(s->session->peer);
    if (EVP_PKEY_get0_RSA(pkey) == NULL) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
        return 0;
    }
    pmslen = SSL_MAX_MASTER_KEY_LENGTH;
    pms = OPENSSL_malloc(pmslen);
    if (pms == NULL) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);
        *al = SSL_AD_INTERNAL_ERROR;
        return 0;
    }
    pms[0] = s->client_version >> 8;
    pms[1] = s->client_version & 0xff;
    if (RAND_bytes(pms + 2, pmslen - 2) <= 0) {
        goto err;
    }
    q = *p;
    if (s->version > SSL3_VERSION)
        *p += 2;
    pctx = EVP_PKEY_CTX_new(pkey, NULL);
    if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0
        || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);
        goto err;
    }
    if (EVP_PKEY_encrypt(pctx, *p, &enclen, pms, pmslen) <= 0) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);
        goto err;
    }
    *len = enclen;
    EVP_PKEY_CTX_free(pctx);
    pctx = NULL;
# ifdef PKCS1_CHECK
    if (s->options & SSL_OP_PKCS1_CHECK_1)
        (*p)[1]++;
    if (s->options & SSL_OP_PKCS1_CHECK_2)
        tmp_buf[0] = 0x70;
# endif
    if (s->version > SSL3_VERSION) {
        s2n(*len, q);
        *len += 2;
    }
    s->s3->tmp.pms = pms;
    s->s3->tmp.pmslen = pmslen;
    return 1;
 err:
    OPENSSL_clear_free(pms, pmslen);
    EVP_PKEY_CTX_free(pctx);
    return 0;
#else
    SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
    *al = SSL_AD_INTERNAL_ERROR;
    return 0;
#endif
}
['static int tls_construct_cke_rsa(SSL *s, unsigned char **p, int *len, int *al)\n{\n#ifndef OPENSSL_NO_RSA\n    unsigned char *q;\n    EVP_PKEY *pkey = NULL;\n    EVP_PKEY_CTX *pctx = NULL;\n    size_t enclen;\n    unsigned char *pms = NULL;\n    size_t pmslen = 0;\n    if (s->session->peer == NULL) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n        return 0;\n    }\n    pkey = X509_get0_pubkey(s->session->peer);\n    if (EVP_PKEY_get0_RSA(pkey) == NULL) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n        return 0;\n    }\n    pmslen = SSL_MAX_MASTER_KEY_LENGTH;\n    pms = OPENSSL_malloc(pmslen);\n    if (pms == NULL) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);\n        *al = SSL_AD_INTERNAL_ERROR;\n        return 0;\n    }\n    pms[0] = s->client_version >> 8;\n    pms[1] = s->client_version & 0xff;\n    if (RAND_bytes(pms + 2, pmslen - 2) <= 0) {\n        goto err;\n    }\n    q = *p;\n    if (s->version > SSL3_VERSION)\n        *p += 2;\n    pctx = EVP_PKEY_CTX_new(pkey, NULL);\n    if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0\n        || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);\n        goto err;\n    }\n    if (EVP_PKEY_encrypt(pctx, *p, &enclen, pms, pmslen) <= 0) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);\n        goto err;\n    }\n    *len = enclen;\n    EVP_PKEY_CTX_free(pctx);\n    pctx = NULL;\n# ifdef PKCS1_CHECK\n    if (s->options & SSL_OP_PKCS1_CHECK_1)\n        (*p)[1]++;\n    if (s->options & SSL_OP_PKCS1_CHECK_2)\n        tmp_buf[0] = 0x70;\n# endif\n    if (s->version > SSL3_VERSION) {\n        s2n(*len, q);\n        *len += 2;\n    }\n    s->s3->tmp.pms = pms;\n    s->s3->tmp.pmslen = pmslen;\n    return 1;\n err:\n    OPENSSL_clear_free(pms, pmslen);\n    EVP_PKEY_CTX_free(pctx);\n    return 0;\n#else\n    SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n    *al = SSL_AD_INTERNAL_ERROR;\n    return 0;\n#endif\n}', 'EVP_PKEY *X509_get0_pubkey(X509 *x)\n{\n    if (x == NULL)\n        return NULL;\n    return X509_PUBKEY_get0(x->cert_info.key);\n}', 'RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)\n{\n    if (pkey->type != EVP_PKEY_RSA) {\n        EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);\n        return NULL;\n    }\n    return pkey->pkey.rsa;\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 RAND_bytes(unsigned char *buf, int num)\n{\n    const RAND_METHOD *meth = RAND_get_rand_method();\n    if (meth && meth->bytes)\n        return meth->bytes(buf, num);\n    return (-1);\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n    if (!default_RAND_meth) {\n#ifndef OPENSSL_NO_ENGINE\n        ENGINE *e = ENGINE_get_default_RAND();\n        if (e) {\n            default_RAND_meth = ENGINE_get_RAND(e);\n            if (default_RAND_meth == NULL) {\n                ENGINE_finish(e);\n                e = NULL;\n            }\n        }\n        if (e)\n            funct_ref = e;\n        else\n#endif\n            default_RAND_meth = RAND_OpenSSL();\n    }\n    return default_RAND_meth;\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}']