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


ssl/statem/statem_clnt.c:2959:1: start of procedure tls_construct_cke_rsa()
2957.   }
2958.   
2959. > static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt)
2960.   {
2961.   #ifndef OPENSSL_NO_RSA

ssl/statem/statem_clnt.c:2962:5: 
2960.   {
2961.   #ifndef OPENSSL_NO_RSA
2962. >     unsigned char *encdata = NULL;
2963.       EVP_PKEY *pkey = NULL;
2964.       EVP_PKEY_CTX *pctx = NULL;

ssl/statem/statem_clnt.c:2963:5: 
2961.   #ifndef OPENSSL_NO_RSA
2962.       unsigned char *encdata = NULL;
2963. >     EVP_PKEY *pkey = NULL;
2964.       EVP_PKEY_CTX *pctx = NULL;
2965.       size_t enclen;

ssl/statem/statem_clnt.c:2964:5: 
2962.       unsigned char *encdata = NULL;
2963.       EVP_PKEY *pkey = NULL;
2964. >     EVP_PKEY_CTX *pctx = NULL;
2965.       size_t enclen;
2966.       unsigned char *pms = NULL;

ssl/statem/statem_clnt.c:2966:5: 
2964.       EVP_PKEY_CTX *pctx = NULL;
2965.       size_t enclen;
2966. >     unsigned char *pms = NULL;
2967.       size_t pmslen = 0;
2968.   

ssl/statem/statem_clnt.c:2967:5: 
2965.       size_t enclen;
2966.       unsigned char *pms = NULL;
2967. >     size_t pmslen = 0;
2968.   
2969.       if (s->session->peer == NULL) {

ssl/statem/statem_clnt.c:2969:9: Taking false branch
2967.       size_t pmslen = 0;
2968.   
2969.       if (s->session->peer == NULL) {
                ^
2970.           /*
2971.            * We should always have a server certificate with SSL_kRSA.

ssl/statem/statem_clnt.c:2978:5: 
2976.       }
2977.   
2978. >     pkey = X509_get0_pubkey(s->session->peer);
2979.       if (EVP_PKEY_get0_RSA(pkey) == NULL) {
2980.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,

crypto/x509/x509_cmp.c:264:1: start of procedure X509_get0_pubkey()
  262.   }
  263.   
  264. > EVP_PKEY *X509_get0_pubkey(const X509 *x)
  265.   {
  266.       if (x == NULL)

crypto/x509/x509_cmp.c:266:9: Taking false branch
  264.   EVP_PKEY *X509_get0_pubkey(const X509 *x)
  265.   {
  266.       if (x == NULL)
                 ^
  267.           return NULL;
  268.       return X509_PUBKEY_get0(x->cert_info.key);

crypto/x509/x509_cmp.c:268:5: 
  266.       if (x == NULL)
  267.           return NULL;
  268. >     return X509_PUBKEY_get0(x->cert_info.key);
  269.   }
  270.   

crypto/x509/x_pubkey.c:141:1: start of procedure X509_PUBKEY_get0()
    139.   }
    140.   
    141. > EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)
    142.   {
    143.       EVP_PKEY *ret = NULL;

crypto/x509/x_pubkey.c:143:5: 
    141.   EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)
    142.   {
    143. >     EVP_PKEY *ret = NULL;
    144.   
    145.       if (key == NULL || key->public_key == NULL)

crypto/x509/x_pubkey.c:145:9: Taking false branch
    143.       EVP_PKEY *ret = NULL;
    144.   
    145.       if (key == NULL || key->public_key == NULL)
                   ^
    146.           return NULL;
    147.   

crypto/x509/x_pubkey.c:145:24: Taking false branch
    143.       EVP_PKEY *ret = NULL;
    144.   
    145.       if (key == NULL || key->public_key == NULL)
                                  ^
    146.           return NULL;
    147.   

crypto/x509/x_pubkey.c:148:9: Taking true branch
    146.           return NULL;
    147.   
    148.       if (key->pkey != NULL)
                   ^
    149.           return key->pkey;
    150.   

crypto/x509/x_pubkey.c:149:9: 
    147.   
    148.       if (key->pkey != NULL)
    149. >         return key->pkey;
    150.   
    151.       /*

crypto/x509/x_pubkey.c:167:1: return from a call to X509_PUBKEY_get0
    165.   
    166.       return NULL;
    167. > }
    168.   
    169.   EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)

crypto/x509/x509_cmp.c:269:1: return from a call to X509_get0_pubkey
  267.           return NULL;
  268.       return X509_PUBKEY_get0(x->cert_info.key);
  269. > }
  270.   
  271.   EVP_PKEY *X509_get_pubkey(X509 *x)

ssl/statem/statem_clnt.c:2979:9: 
2977.   
2978.       pkey = X509_get0_pubkey(s->session->peer);
2979. >     if (EVP_PKEY_get0_RSA(pkey) == NULL) {
2980.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
2981.                    ERR_R_INTERNAL_ERROR);

crypto/evp/p_lib.c:468:1: start of procedure EVP_PKEY_get0_RSA()
  466.   }
  467.   
  468. > RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey)
  469.   {
  470.       if (pkey->type != EVP_PKEY_RSA) {

crypto/evp/p_lib.c:470:9: Taking false branch
  468.   RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey)
  469.   {
  470.       if (pkey->type != EVP_PKEY_RSA) {
                 ^
  471.           EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
  472.           return NULL;

crypto/evp/p_lib.c:474:5: 
  472.           return NULL;
  473.       }
  474. >     return pkey->pkey.rsa;
  475.   }
  476.   

crypto/evp/p_lib.c:475:1: return from a call to EVP_PKEY_get0_RSA
  473.       }
  474.       return pkey->pkey.rsa;
  475. > }
  476.   
  477.   RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)

ssl/statem/statem_clnt.c:2979:9: Taking false branch
2977.   
2978.       pkey = X509_get0_pubkey(s->session->peer);
2979.       if (EVP_PKEY_get0_RSA(pkey) == NULL) {
                ^
2980.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
2981.                    ERR_R_INTERNAL_ERROR);

ssl/statem/statem_clnt.c:2985:5: 
2983.       }
2984.   
2985. >     pmslen = SSL_MAX_MASTER_KEY_LENGTH;
2986.       pms = OPENSSL_malloc(pmslen);
2987.       if (pms == NULL) {

ssl/statem/statem_clnt.c:2986:5: 
2984.   
2985.       pmslen = SSL_MAX_MASTER_KEY_LENGTH;
2986. >     pms = OPENSSL_malloc(pmslen);
2987.       if (pms == NULL) {
2988.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,

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:9: Taking true branch
  202.   
  203.       FAILTEST();
  204.       if (allow_customize) {
                 ^
  205.           /*
  206.            * Disallow customization after the first allocation. We only set this

crypto/mem.c:210:9: 
  208.            * allocation.
  209.            */
  210. >         allow_customize = 0;
  211.       }
  212.   #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)

crypto/mem.c:221:5: 
  219.       }
  220.   #else
  221. >     (void)(file); (void)(line);
  222.       ret = malloc(num);
  223.   #endif

crypto/mem.c:221:19: 
  219.       }
  220.   #else
  221. >     (void)(file); (void)(line);
  222.       ret = malloc(num);
  223.   #endif

crypto/mem.c:222:5: 
  220.   #else
  221.       (void)(file); (void)(line);
  222. >     ret = malloc(num);
  223.   #endif
  224.   

crypto/mem.c:225:5: 
  223.   #endif
  224.   
  225. >     return ret;
  226.   }
  227.   

crypto/mem.c:226:1: return from a call to CRYPTO_malloc
  224.   
  225.       return ret;
  226. > }
  227.   
  228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

ssl/statem/statem_clnt.c:2987:9: Taking false branch
2985.       pmslen = SSL_MAX_MASTER_KEY_LENGTH;
2986.       pms = OPENSSL_malloc(pmslen);
2987.       if (pms == NULL) {
                ^
2988.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
2989.                    ERR_R_MALLOC_FAILURE);

ssl/statem/statem_clnt.c:2993:5: 
2991.       }
2992.   
2993. >     pms[0] = s->client_version >> 8;
2994.       pms[1] = s->client_version & 0xff;
2995.       /* TODO(size_t): Convert this function */

ssl/statem/statem_clnt.c:2994:5: 
2992.   
2993.       pms[0] = s->client_version >> 8;
2994. >     pms[1] = s->client_version & 0xff;
2995.       /* TODO(size_t): Convert this function */
2996.       if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {

ssl/statem/statem_clnt.c:2996:9: 
2994.       pms[1] = s->client_version & 0xff;
2995.       /* TODO(size_t): Convert this function */
2996. >     if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {
2997.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
2998.                    ERR_R_MALLOC_FAILURE);

crypto/rand/rand_lib.c:795:1: start of procedure RAND_bytes()
  793.   }
  794.   
  795. > int RAND_bytes(unsigned char *buf, int num)
  796.   {
  797.       return rand_bytes_ex(NULL, buf, num);

crypto/rand/rand_lib.c:797:5: 
  795.   int RAND_bytes(unsigned char *buf, int num)
  796.   {
  797. >     return rand_bytes_ex(NULL, buf, num);
  798.   }
  799.   

crypto/rand/rand_lib.c:774:1: start of procedure rand_bytes_ex()
    772.   }
    773.   
    774. > int rand_bytes_ex(OPENSSL_CTX *ctx, unsigned char *buf, int num)
    775.   {
    776.       RAND_DRBG *drbg;

crypto/rand/rand_lib.c:778:5: 
    776.       RAND_DRBG *drbg;
    777.       int ret;
    778. >     const RAND_METHOD *meth = RAND_get_rand_method();
    779.   
    780.       if (meth != RAND_OpenSSL()) {

crypto/rand/rand_lib.c:671:1: start of procedure RAND_get_rand_method()
      669.   #endif
      670.   
      671. > const RAND_METHOD *RAND_get_rand_method(void)
      672.   {
      673.   #ifdef FIPS_MODE

crypto/rand/rand_lib.c:674:5: 
      672.   {
      673.   #ifdef FIPS_MODE
      674. >     return NULL;
      675.   #else
      676.       const RAND_METHOD *tmp_meth = NULL;

crypto/rand/rand_lib.c:703:1: return from a call to RAND_get_rand_method
      701.       return tmp_meth;
      702.   #endif
      703. > }
      704.   
      705.   #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)

crypto/rand/rand_lib.c:780:9: 
    778.       const RAND_METHOD *meth = RAND_get_rand_method();
    779.   
    780. >     if (meth != RAND_OpenSSL()) {
    781.           if (meth->bytes != NULL)
    782.               return meth->bytes(buf, num);

crypto/rand/drbg_lib.c:1393:1: start of procedure RAND_OpenSSL()
      1391.   };
      1392.   
      1393. > RAND_METHOD *RAND_OpenSSL(void)
      1394.   {
      1395.   #ifndef FIPS_MODE

crypto/rand/drbg_lib.c:1398:5: 
      1396.       return &rand_meth;
      1397.   #else
      1398. >     return NULL;
      1399.   #endif
      1400.   }

crypto/rand/drbg_lib.c:1400:1: return from a call to RAND_OpenSSL
      1398.       return NULL;
      1399.   #endif
      1400. > }

crypto/rand/rand_lib.c:780:9: Taking false branch
    778.       const RAND_METHOD *meth = RAND_get_rand_method();
    779.   
    780.       if (meth != RAND_OpenSSL()) {
                   ^
    781.           if (meth->bytes != NULL)
    782.               return meth->bytes(buf, num);

crypto/rand/rand_lib.c:787:5: 
    785.       }
    786.   
    787. >     drbg = OPENSSL_CTX_get0_public_drbg(ctx);
    788.       if (drbg == NULL)
    789.           return 0;

crypto/rand/drbg_lib.c:1332:1: start of procedure OPENSSL_CTX_get0_public_drbg()
      1330.    * Returns pointer to the DRBG on success, NULL on failure.
      1331.    */
      1332. > RAND_DRBG *OPENSSL_CTX_get0_public_drbg(OPENSSL_CTX *ctx)
      1333.   {
      1334.       DRBG_GLOBAL *dgbl = drbg_get_global(ctx);

crypto/rand/drbg_lib.c:1334:5: 
      1332.   RAND_DRBG *OPENSSL_CTX_get0_public_drbg(OPENSSL_CTX *ctx)
      1333.   {
      1334. >     DRBG_GLOBAL *dgbl = drbg_get_global(ctx);
      1335.       RAND_DRBG *drbg;
      1336.   

crypto/rand/drbg_lib.c:243:1: start of procedure drbg_get_global()
        241.   };
        242.   
        243. > static DRBG_GLOBAL *drbg_get_global(OPENSSL_CTX *libctx)
        244.   {
        245.       return openssl_ctx_get_data(libctx, OPENSSL_CTX_DRBG_INDEX,

crypto/rand/drbg_lib.c:245:5: 
        243.   static DRBG_GLOBAL *drbg_get_global(OPENSSL_CTX *libctx)
        244.   {
        245. >     return openssl_ctx_get_data(libctx, OPENSSL_CTX_DRBG_INDEX,
        246.                                   &drbg_ossl_ctx_method);
        247.   }

crypto/context.c:186:1: start of procedure openssl_ctx_get_data()
          184.   }
          185.   
          186. > void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,
          187.                              const OPENSSL_CTX_METHOD *meth)
          188.   {

crypto/context.c:189:5: 
          187.                              const OPENSSL_CTX_METHOD *meth)
          188.   {
          189. >     void *data = NULL;
          190.   
          191.       ctx = openssl_ctx_get_concrete(ctx);

crypto/context.c:191:5: 
          189.       void *data = NULL;
          190.   
          191. >     ctx = openssl_ctx_get_concrete(ctx);
          192.       if (ctx == NULL)
          193.           return NULL;

crypto/context.c:134:1: start of procedure openssl_ctx_get_concrete()
            132.   }
            133.   
            134. > OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx)
            135.   {
            136.   #ifndef FIPS_MODE

crypto/context.c:143:5: 
            141.       }
            142.   #endif
            143. >     return ctx;
            144.   }
            145.   

crypto/context.c:144:1: return from a call to openssl_ctx_get_concrete
            142.   #endif
            143.       return ctx;
            144. > }
            145.   
            146.   static void openssl_ctx_generic_new(void *parent_ign, void *ptr_ign,

crypto/context.c:192:9: Taking true branch
          190.   
          191.       ctx = openssl_ctx_get_concrete(ctx);
          192.       if (ctx == NULL)
                         ^
          193.           return NULL;
          194.   

crypto/context.c:193:9: 
          191.       ctx = openssl_ctx_get_concrete(ctx);
          192.       if (ctx == NULL)
          193. >         return NULL;
          194.   
          195.       CRYPTO_THREAD_read_lock(ctx->lock);

crypto/context.c:211:1: return from a call to openssl_ctx_get_data
          209.   
          210.       return data;
          211. > }
          212.   
          213.   OSSL_EX_DATA_GLOBAL *openssl_ctx_get_ex_data_global(OPENSSL_CTX *ctx)

crypto/rand/drbg_lib.c:247:1: return from a call to drbg_get_global
        245.       return openssl_ctx_get_data(libctx, OPENSSL_CTX_DRBG_INDEX,
        246.                                   &drbg_ossl_ctx_method);
        247. > }
        248.   
        249.   /* Implements the get_nonce() callback (see RAND_DRBG_set_callbacks()) */

crypto/rand/drbg_lib.c:1337:9: Taking true branch
      1335.       RAND_DRBG *drbg;
      1336.   
      1337.       if (dgbl == NULL)
                      ^
      1338.           return NULL;
      1339.   

crypto/rand/drbg_lib.c:1338:9: 
      1336.   
      1337.       if (dgbl == NULL)
      1338. >         return NULL;
      1339.   
      1340.       drbg = CRYPTO_THREAD_get_local(&dgbl->public_drbg);

crypto/rand/drbg_lib.c:1349:1: return from a call to OPENSSL_CTX_get0_public_drbg
      1347.       }
      1348.       return drbg;
      1349. > }
      1350.   
      1351.   RAND_DRBG *RAND_DRBG_get0_public(void)

crypto/rand/rand_lib.c:788:9: Taking true branch
    786.   
    787.       drbg = OPENSSL_CTX_get0_public_drbg(ctx);
    788.       if (drbg == NULL)
                   ^
    789.           return 0;
    790.   

crypto/rand/rand_lib.c:789:9: 
    787.       drbg = OPENSSL_CTX_get0_public_drbg(ctx);
    788.       if (drbg == NULL)
    789. >         return 0;
    790.   
    791.       ret = RAND_DRBG_bytes(drbg, buf, num);

crypto/rand/rand_lib.c:793:1: return from a call to rand_bytes_ex
    791.       ret = RAND_DRBG_bytes(drbg, buf, num);
    792.       return ret;
    793. > }
    794.   
    795.   int RAND_bytes(unsigned char *buf, int num)

crypto/rand/rand_lib.c:798:1: return from a call to RAND_bytes
  796.   {
  797.       return rand_bytes_ex(NULL, buf, num);
  798. > }
  799.   
  800.   #if !OPENSSL_API_1_1_0 && !defined(FIPS_MODE)

ssl/statem/statem_clnt.c:2996:9: Taking true branch
2994.       pms[1] = s->client_version & 0xff;
2995.       /* TODO(size_t): Convert this function */
2996.       if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {
                ^
2997.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
2998.                    ERR_R_MALLOC_FAILURE);

ssl/statem/statem_clnt.c:2997:9: 
2995.       /* TODO(size_t): Convert this function */
2996.       if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {
2997. >         SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
2998.                    ERR_R_MALLOC_FAILURE);
2999.           goto err;

test/tls13secretstest.c:194:1: start of procedure ossl_statem_fatal()
  192.   }
  193.   
  194. > void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,
  195.                              int line)
  196.   {

test/tls13secretstest.c:197:1: return from a call to ossl_statem_fatal
  195.                              int line)
  196.   {
  197. > }
  198.   
  199.   int ossl_statem_export_allowed(SSL *s)

ssl/statem/statem_clnt.c:3041:2: 
3039.   
3040.       return 1;
3041. >  err:
3042.       OPENSSL_clear_free(pms, pmslen);
3043.       EVP_PKEY_CTX_free(pctx);

ssl/statem/statem_clnt.c:3042:5: 
3040.       return 1;
3041.    err:
3042. >     OPENSSL_clear_free(pms, pmslen);
3043.       EVP_PKEY_CTX_free(pctx);
3044.   

crypto/mem.c:316:1: start of procedure CRYPTO_clear_free()
  314.   }
  315.   
  316. > void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  317.   {
  318.       if (str == NULL)

crypto/mem.c:318:9: Taking false branch
  316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  317.   {
  318.       if (str == NULL)
                 ^
  319.           return;
  320.       if (num)

crypto/mem.c:320:9: Taking true branch
  318.       if (str == NULL)
  319.           return;
  320.       if (num)
                 ^
  321.           OPENSSL_cleanse(str, num);
  322.       CRYPTO_free(str, file, line);

crypto/mem.c:321:9: Skipping OPENSSL_cleanse(): method has no implementation
  319.           return;
  320.       if (num)
  321.           OPENSSL_cleanse(str, num);
                 ^
  322.       CRYPTO_free(str, file, line);
  323.   }

crypto/mem.c:322:5: 
  320.       if (num)
  321.           OPENSSL_cleanse(str, num);
  322. >     CRYPTO_free(str, file, line);
  323.   }

crypto/mem.c:295:1: start of procedure CRYPTO_free()
    293.   }
    294.   
    295. > void CRYPTO_free(void *str, const char *file, int line)
    296.   {
    297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:298:30: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
                   ^
    300.           return;
    301.       }

crypto/mem.c:300:9: 
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
    300. >         return;
    301.       }
    302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
    312.       free(str);
    313.   #endif
    314. > }
    315.   
    316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

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

static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt)
{
#ifndef OPENSSL_NO_RSA
    unsigned char *encdata = NULL;
    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) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, 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) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, 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) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
                 ERR_R_MALLOC_FAILURE);
        return 0;
    }
    pms[0] = s->client_version >> 8;
    pms[1] = s->client_version & 0xff;
    if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
                 ERR_R_MALLOC_FAILURE);
        goto err;
    }
    if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
                 ERR_R_INTERNAL_ERROR);
        goto err;
    }
    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) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
                 ERR_R_EVP_LIB);
        goto err;
    }
    if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)
            || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
                 SSL_R_BAD_RSA_ENCRYPT);
        goto err;
    }
    EVP_PKEY_CTX_free(pctx);
    pctx = NULL;
    if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
                 ERR_R_INTERNAL_ERROR);
        goto err;
    }
    if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen)) {
        goto err;
    }
    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
    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
             ERR_R_INTERNAL_ERROR);
    return 0;
#endif
}
['static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt)\n{\n#ifndef OPENSSL_NO_RSA\n    unsigned char *encdata = NULL;\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        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n                 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        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n                 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        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n                 ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    pms[0] = s->client_version >> 8;\n    pms[1] = s->client_version & 0xff;\n    if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n                 ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n                 ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\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        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n                 ERR_R_EVP_LIB);\n        goto err;\n    }\n    if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)\n            || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n                 SSL_R_BAD_RSA_ENCRYPT);\n        goto err;\n    }\n    EVP_PKEY_CTX_free(pctx);\n    pctx = NULL;\n    if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n                 ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen)) {\n        goto err;\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    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n             ERR_R_INTERNAL_ERROR);\n    return 0;\n#endif\n}', 'EVP_PKEY *X509_get0_pubkey(const X509 *x)\n{\n    if (x == NULL)\n        return NULL;\n    return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n    EVP_PKEY *ret = NULL;\n    if (key == NULL || key->public_key == NULL)\n        return NULL;\n    if (key->pkey != NULL)\n        return key->pkey;\n    x509_pubkey_decode(&ret, key);\n    if (ret != NULL) {\n        X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);\n        EVP_PKEY_free(ret);\n    }\n    return NULL;\n}', 'RSA *EVP_PKEY_get0_RSA(const 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    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    if (allow_customize) {\n        allow_customize = 0;\n    }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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}', 'int RAND_bytes(unsigned char *buf, int num)\n{\n    return rand_bytes_ex(NULL, buf, num);\n}', 'int rand_bytes_ex(OPENSSL_CTX *ctx, unsigned char *buf, int num)\n{\n    RAND_DRBG *drbg;\n    int ret;\n    const RAND_METHOD *meth = RAND_get_rand_method();\n    if (meth != RAND_OpenSSL()) {\n        if (meth->bytes != NULL)\n            return meth->bytes(buf, num);\n        RANDerr(RAND_F_RAND_BYTES_EX, RAND_R_FUNC_NOT_IMPLEMENTED);\n        return -1;\n    }\n    drbg = OPENSSL_CTX_get0_public_drbg(ctx);\n    if (drbg == NULL)\n        return 0;\n    ret = RAND_DRBG_bytes(drbg, buf, num);\n    return ret;\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n#ifdef FIPS_MODE\n    return NULL;\n#else\n    const RAND_METHOD *tmp_meth = NULL;\n    if (!RUN_ONCE(&rand_init, do_rand_init))\n        return NULL;\n    CRYPTO_THREAD_write_lock(rand_meth_lock);\n    if (default_RAND_meth == NULL) {\n# ifndef OPENSSL_NO_ENGINE\n        ENGINE *e;\n        if ((e = ENGINE_get_default_RAND()) != NULL\n                && (tmp_meth = ENGINE_get_RAND(e)) != NULL) {\n            funct_ref = e;\n            default_RAND_meth = tmp_meth;\n        } else {\n            ENGINE_finish(e);\n            default_RAND_meth = &rand_meth;\n        }\n# else\n        default_RAND_meth = &rand_meth;\n# endif\n    }\n    tmp_meth = default_RAND_meth;\n    CRYPTO_THREAD_unlock(rand_meth_lock);\n    return tmp_meth;\n#endif\n}', 'RAND_METHOD *RAND_OpenSSL(void)\n{\n#ifndef FIPS_MODE\n    return &rand_meth;\n#else\n    return NULL;\n#endif\n}', 'RAND_DRBG *OPENSSL_CTX_get0_public_drbg(OPENSSL_CTX *ctx)\n{\n    DRBG_GLOBAL *dgbl = drbg_get_global(ctx);\n    RAND_DRBG *drbg;\n    if (dgbl == NULL)\n        return NULL;\n    drbg = CRYPTO_THREAD_get_local(&dgbl->public_drbg);\n    if (drbg == NULL) {\n        ctx = openssl_ctx_get_concrete(ctx);\n        if (!ossl_init_thread_start(NULL, ctx, drbg_delete_thread_state))\n            return NULL;\n        drbg = drbg_setup(ctx, dgbl->master_drbg, RAND_DRBG_TYPE_PUBLIC);\n        CRYPTO_THREAD_set_local(&dgbl->public_drbg, drbg);\n    }\n    return drbg;\n}', 'static DRBG_GLOBAL *drbg_get_global(OPENSSL_CTX *libctx)\n{\n    return openssl_ctx_get_data(libctx, OPENSSL_CTX_DRBG_INDEX,\n                                &drbg_ossl_ctx_method);\n}', 'void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,\n                           const OPENSSL_CTX_METHOD *meth)\n{\n    void *data = NULL;\n    ctx = openssl_ctx_get_concrete(ctx);\n    if (ctx == NULL)\n        return NULL;\n    CRYPTO_THREAD_read_lock(ctx->lock);\n    if (ctx->dyn_indexes[index] == -1\n            && !openssl_ctx_init_index(ctx, index, meth)) {\n        CRYPTO_THREAD_unlock(ctx->lock);\n        return NULL;\n    }\n    if (CRYPTO_alloc_ex_data(CRYPTO_EX_INDEX_OPENSSL_CTX, NULL,\n                             &ctx->data, ctx->dyn_indexes[index]))\n        data = CRYPTO_get_ex_data(&ctx->data, ctx->dyn_indexes[index]);\n    CRYPTO_THREAD_unlock(ctx->lock);\n    return data;\n}', 'OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx)\n{\n#ifndef FIPS_MODE\n    if (ctx == NULL) {\n        if (!RUN_ONCE(&default_context_init, do_default_context_init))\n            return 0;\n        return default_context;\n    }\n#endif\n    return ctx;\n}', 'void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,\n                           int line)\n{\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    INCREMENT(free_count);\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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}']