ssl/statem/statem_lib.c:504: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 354, column 24 is not reachable after line 504, column 5.
Showing all 68 steps of the trace


ssl/statem/statem_lib.c:339:1: start of procedure tls_process_cert_verify()
337.   }
338.   
339. > MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
340.   {
341.       EVP_PKEY *pkey = NULL;

ssl/statem/statem_lib.c:341:5: 
339.   MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
340.   {
341. >     EVP_PKEY *pkey = NULL;
342.       const unsigned char *data;
343.   #ifndef OPENSSL_NO_GOST

ssl/statem/statem_lib.c:344:5: 
342.       const unsigned char *data;
343.   #ifndef OPENSSL_NO_GOST
344. >     unsigned char *gost_data = NULL;
345.   #endif
346.       MSG_PROCESS_RETURN ret = MSG_PROCESS_ERROR;

ssl/statem/statem_lib.c:346:5: 
344.       unsigned char *gost_data = NULL;
345.   #endif
346. >     MSG_PROCESS_RETURN ret = MSG_PROCESS_ERROR;
347.       int j;
348.       unsigned int len;

ssl/statem/statem_lib.c:350:5: 
348.       unsigned int len;
349.       X509 *peer;
350. >     const EVP_MD *md = NULL;
351.       size_t hdatalen = 0;
352.       void *hdata;

ssl/statem/statem_lib.c:351:5: 
349.       X509 *peer;
350.       const EVP_MD *md = NULL;
351. >     size_t hdatalen = 0;
352.       void *hdata;
353.       unsigned char tls13tbs[TLS13_TBS_PREAMBLE_SIZE + EVP_MAX_MD_SIZE];

ssl/statem/statem_lib.c:354:5: 
352.       void *hdata;
353.       unsigned char tls13tbs[TLS13_TBS_PREAMBLE_SIZE + EVP_MAX_MD_SIZE];
354. >     EVP_MD_CTX *mctx = EVP_MD_CTX_new();
355.       EVP_PKEY_CTX *pctx = NULL;
356.   

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:228:1: start of procedure CRYPTO_zalloc()
    226.   }
    227.   
    228. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:230:5: 
    228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230. >     void *ret = CRYPTO_malloc(num, file, line);
    231.   
    232.       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: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.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

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)

crypto/mem.c:233:9: Taking true branch
    231.   
    232.       FAILTEST();
    233.       if (ret != NULL)
                   ^
    234.           memset(ret, 0, num);
    235.       return ret;

crypto/mem.c:234:9: 
    232.       FAILTEST();
    233.       if (ret != NULL)
    234. >         memset(ret, 0, num);
    235.       return ret;
    236.   }

crypto/mem.c:235:5: 
    233.       if (ret != NULL)
    234.           memset(ret, 0, num);
    235. >     return ret;
    236.   }
    237.   

crypto/mem.c:236:1: return from a call to CRYPTO_zalloc
    234.           memset(ret, 0, num);
    235.       return ret;
    236. > }
    237.   
    238.   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/statem/statem_lib.c:355:5: 
353.       unsigned char tls13tbs[TLS13_TBS_PREAMBLE_SIZE + EVP_MAX_MD_SIZE];
354.       EVP_MD_CTX *mctx = EVP_MD_CTX_new();
355. >     EVP_PKEY_CTX *pctx = NULL;
356.   
357.       if (mctx == NULL) {

ssl/statem/statem_lib.c:357:9: Taking false branch
355.       EVP_PKEY_CTX *pctx = NULL;
356.   
357.       if (mctx == NULL) {
               ^
358.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
359.                    ERR_R_MALLOC_FAILURE);

ssl/statem/statem_lib.c:363:5: 
361.       }
362.   
363. >     peer = s->session->peer;
364.       pkey = X509_get0_pubkey(peer);
365.       if (pkey == NULL) {

ssl/statem/statem_lib.c:364:5: 
362.   
363.       peer = s->session->peer;
364. >     pkey = X509_get0_pubkey(peer);
365.       if (pkey == NULL) {
366.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,

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:140:1: start of procedure X509_PUBKEY_get0()
    138.   }
    139.   
    140. > EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)
    141.   {
    142.       EVP_PKEY *ret = NULL;

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

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

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

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

crypto/x509/x_pubkey.c:158:5: 
    156.        * in the queue.
    157.        */
    158. >     x509_pubkey_decode(&ret, key);
    159.       /* If decode doesn't fail something bad happened */
    160.       if (ret != NULL) {

crypto/x509/x_pubkey.c:103:1: start of procedure x509_pubkey_decode()
      101.   
      102.   
      103. > static int x509_pubkey_decode(EVP_PKEY **ppkey, X509_PUBKEY *key)
      104.   {
      105.       EVP_PKEY *pkey = EVP_PKEY_new();

crypto/x509/x_pubkey.c:105:5: Skipping EVP_PKEY_new(): empty list of specs
      103.   static int x509_pubkey_decode(EVP_PKEY **ppkey, X509_PUBKEY *key)
      104.   {
      105.       EVP_PKEY *pkey = EVP_PKEY_new();
                 ^
      106.   
      107.       if (pkey == NULL) {

crypto/x509/x_pubkey.c:107:9: Taking true branch
      105.       EVP_PKEY *pkey = EVP_PKEY_new();
      106.   
      107.       if (pkey == NULL) {
                     ^
      108.           X509err(X509_F_X509_PUBKEY_DECODE, ERR_R_MALLOC_FAILURE);
      109.           return -1;

crypto/x509/x_pubkey.c:108:9: Skipping ERR_put_error(): empty list of specs
      106.   
      107.       if (pkey == NULL) {
      108.           X509err(X509_F_X509_PUBKEY_DECODE, ERR_R_MALLOC_FAILURE);
                     ^
      109.           return -1;
      110.       }

crypto/x509/x_pubkey.c:109:9: 
      107.       if (pkey == NULL) {
      108.           X509err(X509_F_X509_PUBKEY_DECODE, ERR_R_MALLOC_FAILURE);
      109. >         return -1;
      110.       }
      111.   

crypto/x509/x_pubkey.c:138:1: return from a call to x509_pubkey_decode
      136.       EVP_PKEY_free(pkey);
      137.       return 0;
      138. > }
      139.   
      140.   EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)

crypto/x509/x_pubkey.c:160:9: Taking false branch
    158.       x509_pubkey_decode(&ret, key);
    159.       /* If decode doesn't fail something bad happened */
    160.       if (ret != NULL) {
                   ^
    161.           X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);
    162.           EVP_PKEY_free(ret);

crypto/x509/x_pubkey.c:165:5: 
    163.       }
    164.   
    165. >     return NULL;
    166.   }
    167.   

crypto/x509/x_pubkey.c:166:1: return from a call to X509_PUBKEY_get0
    164.   
    165.       return NULL;
    166. > }
    167.   
    168.   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_lib.c:365:9: Taking true branch
363.       peer = s->session->peer;
364.       pkey = X509_get0_pubkey(peer);
365.       if (pkey == NULL) {
               ^
366.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
367.                    ERR_R_INTERNAL_ERROR);

ssl/statem/statem_lib.c:366:9: 
364.       pkey = X509_get0_pubkey(peer);
365.       if (pkey == NULL) {
366. >         SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
367.                    ERR_R_INTERNAL_ERROR);
368.           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/statem/statem_lib.c:501:2: 
499.   
500.       ret = MSG_PROCESS_CONTINUE_READING;
501. >  err:
502.       BIO_free(s->s3->handshake_buffer);
503.       s->s3->handshake_buffer = NULL;

ssl/statem/statem_lib.c:502:5: Skipping BIO_free(): empty list of specs
500.       ret = MSG_PROCESS_CONTINUE_READING;
501.    err:
502.       BIO_free(s->s3->handshake_buffer);
           ^
503.       s->s3->handshake_buffer = NULL;
504.       EVP_MD_CTX_free(mctx);

ssl/statem/statem_lib.c:503:5: 
501.    err:
502.       BIO_free(s->s3->handshake_buffer);
503. >     s->s3->handshake_buffer = NULL;
504.       EVP_MD_CTX_free(mctx);
505.   #ifndef OPENSSL_NO_GOST

ssl/statem/statem_lib.c:504:5: 
502.       BIO_free(s->s3->handshake_buffer);
503.       s->s3->handshake_buffer = NULL;
504. >     EVP_MD_CTX_free(mctx);
505.   #ifndef OPENSSL_NO_GOST
506.       OPENSSL_free(gost_data);

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

MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
{
    EVP_PKEY *pkey = NULL;
    const unsigned char *data;
#ifndef OPENSSL_NO_GOST
    unsigned char *gost_data = NULL;
#endif
    MSG_PROCESS_RETURN ret = MSG_PROCESS_ERROR;
    int j;
    unsigned int len;
    X509 *peer;
    const EVP_MD *md = NULL;
    size_t hdatalen = 0;
    void *hdata;
    unsigned char tls13tbs[TLS13_TBS_PREAMBLE_SIZE + EVP_MAX_MD_SIZE];
    EVP_MD_CTX *mctx = EVP_MD_CTX_new();
    EVP_PKEY_CTX *pctx = NULL;
    if (mctx == NULL) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                 ERR_R_MALLOC_FAILURE);
        goto err;
    }
    peer = s->session->peer;
    pkey = X509_get0_pubkey(peer);
    if (pkey == NULL) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                 ERR_R_INTERNAL_ERROR);
        goto err;
    }
    if (ssl_cert_lookup_by_pkey(pkey, NULL) == NULL) {
        SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_F_TLS_PROCESS_CERT_VERIFY,
                 SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);
        goto err;
    }
    if (SSL_USE_SIGALGS(s)) {
        unsigned int sigalg;
        if (!PACKET_get_net_2(pkt, &sigalg)) {
            SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                     SSL_R_BAD_PACKET);
            goto err;
        }
        if (tls12_check_peer_sigalg(s, sigalg, pkey) <= 0) {
            goto err;
        }
#ifdef SSL_DEBUG
        fprintf(stderr, "USING TLSv1.2 HASH %s\n", EVP_MD_name(md));
#endif
    } else if (!tls1_set_peer_legacy_sigalg(s, pkey)) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                     ERR_R_INTERNAL_ERROR);
            goto err;
    }
    if (!tls1_lookup_md(s->s3->tmp.peer_sigalg, &md)) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                 ERR_R_INTERNAL_ERROR);
        goto err;
    }
#ifndef OPENSSL_NO_GOST
    if (!SSL_USE_SIGALGS(s)
        && ((PACKET_remaining(pkt) == 64
             && (EVP_PKEY_id(pkey) == NID_id_GostR3410_2001
                 || EVP_PKEY_id(pkey) == NID_id_GostR3410_2012_256))
            || (PACKET_remaining(pkt) == 128
                && EVP_PKEY_id(pkey) == NID_id_GostR3410_2012_512))) {
        len = PACKET_remaining(pkt);
    } else
#endif
    if (!PACKET_get_net_2(pkt, &len)) {
        SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                 SSL_R_LENGTH_MISMATCH);
        goto err;
    }
    j = EVP_PKEY_size(pkey);
    if (((int)len > j) || ((int)PACKET_remaining(pkt) > j)
        || (PACKET_remaining(pkt) == 0)) {
        SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                 SSL_R_WRONG_SIGNATURE_SIZE);
        goto err;
    }
    if (!PACKET_get_bytes(pkt, &data, len)) {
        SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                 SSL_R_LENGTH_MISMATCH);
        goto err;
    }
    if (!get_cert_verify_tbs_data(s, tls13tbs, &hdata, &hdatalen)) {
        goto err;
    }
#ifdef SSL_DEBUG
    fprintf(stderr, "Using client verify alg %s\n", EVP_MD_name(md));
#endif
    if (EVP_DigestVerifyInit(mctx, &pctx, md, NULL, pkey) <= 0) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                 ERR_R_EVP_LIB);
        goto err;
    }
#ifndef OPENSSL_NO_GOST
    {
        int pktype = EVP_PKEY_id(pkey);
        if (pktype == NID_id_GostR3410_2001
            || pktype == NID_id_GostR3410_2012_256
            || pktype == NID_id_GostR3410_2012_512) {
            if ((gost_data = OPENSSL_malloc(len)) == NULL) {
                SSLfatal(s, SSL_AD_INTERNAL_ERROR,
                         SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_MALLOC_FAILURE);
                goto err;
            }
            BUF_reverse(gost_data, data, len);
            data = gost_data;
        }
    }
#endif
    if (SSL_USE_PSS(s)) {
        if (EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING) <= 0
            || EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx,
                                                RSA_PSS_SALTLEN_DIGEST) <= 0) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                     ERR_R_EVP_LIB);
            goto err;
        }
    }
    if (s->version == SSL3_VERSION) {
        if (EVP_DigestVerifyUpdate(mctx, hdata, hdatalen) <= 0
                || !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET,
                                    (int)s->session->master_key_length,
                                    s->session->master_key)) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                     ERR_R_EVP_LIB);
            goto err;
        }
        if (EVP_DigestVerifyFinal(mctx, data, len) <= 0) {
            SSLfatal(s, SSL_AD_DECRYPT_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                     SSL_R_BAD_SIGNATURE);
            goto err;
        }
    } else {
        j = EVP_DigestVerify(mctx, data, len, hdata, hdatalen);
        if (j <= 0) {
            SSLfatal(s, SSL_AD_DECRYPT_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,
                     SSL_R_BAD_SIGNATURE);
            goto err;
        }
    }
    ret = MSG_PROCESS_CONTINUE_READING;
 err:
    BIO_free(s->s3->handshake_buffer);
    s->s3->handshake_buffer = NULL;
    EVP_MD_CTX_free(mctx);
#ifndef OPENSSL_NO_GOST
    OPENSSL_free(gost_data);
#endif
    return ret;
}
['MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)\n{\n    EVP_PKEY *pkey = NULL;\n    const unsigned char *data;\n#ifndef OPENSSL_NO_GOST\n    unsigned char *gost_data = NULL;\n#endif\n    MSG_PROCESS_RETURN ret = MSG_PROCESS_ERROR;\n    int j;\n    unsigned int len;\n    X509 *peer;\n    const EVP_MD *md = NULL;\n    size_t hdatalen = 0;\n    void *hdata;\n    unsigned char tls13tbs[TLS13_TBS_PREAMBLE_SIZE + EVP_MAX_MD_SIZE];\n    EVP_MD_CTX *mctx = EVP_MD_CTX_new();\n    EVP_PKEY_CTX *pctx = NULL;\n    if (mctx == NULL) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                 ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    peer = s->session->peer;\n    pkey = X509_get0_pubkey(peer);\n    if (pkey == NULL) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                 ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (ssl_cert_lookup_by_pkey(pkey, NULL) == NULL) {\n        SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                 SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);\n        goto err;\n    }\n    if (SSL_USE_SIGALGS(s)) {\n        unsigned int sigalg;\n        if (!PACKET_get_net_2(pkt, &sigalg)) {\n            SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                     SSL_R_BAD_PACKET);\n            goto err;\n        }\n        if (tls12_check_peer_sigalg(s, sigalg, pkey) <= 0) {\n            goto err;\n        }\n#ifdef SSL_DEBUG\n        fprintf(stderr, "USING TLSv1.2 HASH %s\\n", EVP_MD_name(md));\n#endif\n    } else if (!tls1_set_peer_legacy_sigalg(s, pkey)) {\n            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                     ERR_R_INTERNAL_ERROR);\n            goto err;\n    }\n    if (!tls1_lookup_md(s->s3->tmp.peer_sigalg, &md)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                 ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n#ifndef OPENSSL_NO_GOST\n    if (!SSL_USE_SIGALGS(s)\n        && ((PACKET_remaining(pkt) == 64\n             && (EVP_PKEY_id(pkey) == NID_id_GostR3410_2001\n                 || EVP_PKEY_id(pkey) == NID_id_GostR3410_2012_256))\n            || (PACKET_remaining(pkt) == 128\n                && EVP_PKEY_id(pkey) == NID_id_GostR3410_2012_512))) {\n        len = PACKET_remaining(pkt);\n    } else\n#endif\n    if (!PACKET_get_net_2(pkt, &len)) {\n        SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                 SSL_R_LENGTH_MISMATCH);\n        goto err;\n    }\n    j = EVP_PKEY_size(pkey);\n    if (((int)len > j) || ((int)PACKET_remaining(pkt) > j)\n        || (PACKET_remaining(pkt) == 0)) {\n        SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                 SSL_R_WRONG_SIGNATURE_SIZE);\n        goto err;\n    }\n    if (!PACKET_get_bytes(pkt, &data, len)) {\n        SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                 SSL_R_LENGTH_MISMATCH);\n        goto err;\n    }\n    if (!get_cert_verify_tbs_data(s, tls13tbs, &hdata, &hdatalen)) {\n        goto err;\n    }\n#ifdef SSL_DEBUG\n    fprintf(stderr, "Using client verify alg %s\\n", EVP_MD_name(md));\n#endif\n    if (EVP_DigestVerifyInit(mctx, &pctx, md, NULL, pkey) <= 0) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                 ERR_R_EVP_LIB);\n        goto err;\n    }\n#ifndef OPENSSL_NO_GOST\n    {\n        int pktype = EVP_PKEY_id(pkey);\n        if (pktype == NID_id_GostR3410_2001\n            || pktype == NID_id_GostR3410_2012_256\n            || pktype == NID_id_GostR3410_2012_512) {\n            if ((gost_data = OPENSSL_malloc(len)) == NULL) {\n                SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n                         SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_MALLOC_FAILURE);\n                goto err;\n            }\n            BUF_reverse(gost_data, data, len);\n            data = gost_data;\n        }\n    }\n#endif\n    if (SSL_USE_PSS(s)) {\n        if (EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING) <= 0\n            || EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx,\n                                                RSA_PSS_SALTLEN_DIGEST) <= 0) {\n            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                     ERR_R_EVP_LIB);\n            goto err;\n        }\n    }\n    if (s->version == SSL3_VERSION) {\n        if (EVP_DigestVerifyUpdate(mctx, hdata, hdatalen) <= 0\n                || !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET,\n                                    (int)s->session->master_key_length,\n                                    s->session->master_key)) {\n            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                     ERR_R_EVP_LIB);\n            goto err;\n        }\n        if (EVP_DigestVerifyFinal(mctx, data, len) <= 0) {\n            SSLfatal(s, SSL_AD_DECRYPT_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                     SSL_R_BAD_SIGNATURE);\n            goto err;\n        }\n    } else {\n        j = EVP_DigestVerify(mctx, data, len, hdata, hdatalen);\n        if (j <= 0) {\n            SSLfatal(s, SSL_AD_DECRYPT_ERROR, SSL_F_TLS_PROCESS_CERT_VERIFY,\n                     SSL_R_BAD_SIGNATURE);\n            goto err;\n        }\n    }\n    ret = MSG_PROCESS_CONTINUE_READING;\n err:\n    BIO_free(s->s3->handshake_buffer);\n    s->s3->handshake_buffer = NULL;\n    EVP_MD_CTX_free(mctx);\n#ifndef OPENSSL_NO_GOST\n    OPENSSL_free(gost_data);\n#endif\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    if (allow_customize) {\n        allow_customize = 0;\n    }\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}', '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}', 'static int x509_pubkey_decode(EVP_PKEY **ppkey, X509_PUBKEY *key)\n{\n    EVP_PKEY *pkey = EVP_PKEY_new();\n    if (pkey == NULL) {\n        X509err(X509_F_X509_PUBKEY_DECODE, ERR_R_MALLOC_FAILURE);\n        return -1;\n    }\n    if (!EVP_PKEY_set_type(pkey, OBJ_obj2nid(key->algor->algorithm))) {\n        X509err(X509_F_X509_PUBKEY_DECODE, X509_R_UNSUPPORTED_ALGORITHM);\n        goto error;\n    }\n    if (pkey->ameth->pub_decode) {\n        if (!pkey->ameth->pub_decode(pkey, key)) {\n            X509err(X509_F_X509_PUBKEY_DECODE, X509_R_PUBLIC_KEY_DECODE_ERROR);\n            goto error;\n        }\n    } else {\n        X509err(X509_F_X509_PUBKEY_DECODE, X509_R_METHOD_NOT_SUPPORTED);\n        goto error;\n    }\n    *ppkey = pkey;\n    return 1;\n error:\n    EVP_PKEY_free(pkey);\n    return 0;\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}']