ssl/statem/statem_srvr.c:2695: error: NULL_DEREFERENCE
  pointer `pkey` last assigned on line 2678 could be null and is dereferenced by call to `EVP_PKEY_id()` at line 2695, column 12.
Showing all 53 steps of the trace


ssl/statem/statem_srvr.c:2657:1: start of procedure tls_process_cert_verify()
2655.   }
2656.   
2657. > MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
2658.   {
2659.       EVP_PKEY *pkey = NULL;

ssl/statem/statem_srvr.c:2659:5: 
2657.   MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
2658.   {
2659. >     EVP_PKEY *pkey = NULL;
2660.       unsigned char *sig, *data;
2661.       int al, ret = MSG_PROCESS_ERROR;

ssl/statem/statem_srvr.c:2661:5: 
2659.       EVP_PKEY *pkey = NULL;
2660.       unsigned char *sig, *data;
2661. >     int al, ret = MSG_PROCESS_ERROR;
2662.       int type = 0, j;
2663.       unsigned int len;

ssl/statem/statem_srvr.c:2662:5: 
2660.       unsigned char *sig, *data;
2661.       int al, ret = MSG_PROCESS_ERROR;
2662. >     int type = 0, j;
2663.       unsigned int len;
2664.       X509 *peer;

ssl/statem/statem_srvr.c:2665:5: 
2663.       unsigned int len;
2664.       X509 *peer;
2665. >     const EVP_MD *md = NULL;
2666.       long hdatalen = 0;
2667.       void *hdata;

ssl/statem/statem_srvr.c:2666:5: 
2664.       X509 *peer;
2665.       const EVP_MD *md = NULL;
2666. >     long hdatalen = 0;
2667.       void *hdata;
2668.   

ssl/statem/statem_srvr.c:2669:5: 
2667.       void *hdata;
2668.   
2669. >     EVP_MD_CTX *mctx = EVP_MD_CTX_new();
2670.   
2671.       if (mctx == NULL) {

crypto/evp/digest.c:153:1: start of procedure EVP_MD_CTX_new()
  151.   }
  152.   
  153. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  154.   {
  155.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:155:5: 
  153.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  154.   {
  155. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  156.   }
  157.   

crypto/mem.c:157:1: start of procedure CRYPTO_zalloc()
    155.   }
    156.   
    157. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    158.   {
    159.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:159:5: 
    157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    158.   {
    159. >     void *ret = CRYPTO_malloc(num, file, line);
    160.   
    161.       if (ret != NULL)

crypto/mem.c:120:1: start of procedure CRYPTO_malloc()
      118.   }
      119.   
      120. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      121.   {
      122.       void *ret = NULL;

crypto/mem.c:122:5: 
      120.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      121.   {
      122. >     void *ret = NULL;
      123.   
      124.       if (num <= 0)

crypto/mem.c:124:9: Taking false branch
      122.       void *ret = NULL;
      123.   
      124.       if (num <= 0)
                     ^
      125.           return NULL;
      126.   

crypto/mem.c:127:5: 
      125.           return NULL;
      126.   
      127. >     allow_customize = 0;
      128.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      129.       if (call_malloc_debug) {

crypto/mem.c:137:5: 
      135.       }
      136.   #else
      137. >     (void)file;
      138.       (void)line;
      139.       ret = malloc(num);

crypto/mem.c:138:5: 
      136.   #else
      137.       (void)file;
      138. >     (void)line;
      139.       ret = malloc(num);
      140.   #endif

crypto/mem.c:139:5: 
      137.       (void)file;
      138.       (void)line;
      139. >     ret = malloc(num);
      140.   #endif
      141.   

crypto/mem.c:154:5: 
      152.   #endif
      153.   
      154. >     return ret;
      155.   }
      156.   

crypto/mem.c:155:1: return from a call to CRYPTO_malloc
      153.   
      154.       return ret;
      155. > }
      156.   
      157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:161:9: Taking true branch
    159.       void *ret = CRYPTO_malloc(num, file, line);
    160.   
    161.       if (ret != NULL)
                   ^
    162.           memset(ret, 0, num);
    163.       return ret;

crypto/mem.c:162:9: 
    160.   
    161.       if (ret != NULL)
    162. >         memset(ret, 0, num);
    163.       return ret;
    164.   }

crypto/mem.c:163:5: 
    161.       if (ret != NULL)
    162.           memset(ret, 0, num);
    163. >     return ret;
    164.   }
    165.   

crypto/mem.c:164:1: return from a call to CRYPTO_zalloc
    162.           memset(ret, 0, num);
    163.       return ret;
    164. > }
    165.   
    166.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:156:1: return from a call to EVP_MD_CTX_new
  154.   {
  155.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  156. > }
  157.   
  158.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

ssl/statem/statem_srvr.c:2671:9: Taking false branch
2669.       EVP_MD_CTX *mctx = EVP_MD_CTX_new();
2670.   
2671.       if (mctx == NULL) {
                ^
2672.           SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_MALLOC_FAILURE);
2673.           al = SSL_AD_INTERNAL_ERROR;

ssl/statem/statem_srvr.c:2677:5: 
2675.       }
2676.   
2677. >     peer = s->session->peer;
2678.       pkey = X509_get0_pubkey(peer);
2679.       type = X509_certificate_type(peer, pkey);

ssl/statem/statem_srvr.c:2678:5: 
2676.   
2677.       peer = s->session->peer;
2678. >     pkey = X509_get0_pubkey(peer);
2679.       type = X509_certificate_type(peer, pkey);
2680.   

crypto/x509/x509_cmp.c:308:1: start of procedure X509_get0_pubkey()
  306.   }
  307.   
  308. > EVP_PKEY *X509_get0_pubkey(X509 *x)
  309.   {
  310.       if (x == NULL)

crypto/x509/x509_cmp.c:310:9: Taking false branch
  308.   EVP_PKEY *X509_get0_pubkey(X509 *x)
  309.   {
  310.       if (x == NULL)
                 ^
  311.           return NULL;
  312.       return X509_PUBKEY_get0(x->cert_info.key);

crypto/x509/x509_cmp.c:312:5: 
  310.       if (x == NULL)
  311.           return NULL;
  312. >     return X509_PUBKEY_get0(x->cert_info.key);
  313.   }
  314.   

crypto/asn1/x_pubkey.c:125:1: start of procedure X509_PUBKEY_get0()
    123.   }
    124.   
    125. > EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)
    126.   {
    127.       EVP_PKEY *ret = NULL;

crypto/asn1/x_pubkey.c:127:5: 
    125.   EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)
    126.   {
    127. >     EVP_PKEY *ret = NULL;
    128.   
    129.       if (key == NULL)

crypto/asn1/x_pubkey.c:129:9: Taking true branch
    127.       EVP_PKEY *ret = NULL;
    128.   
    129.       if (key == NULL)
                   ^
    130.           goto error;
    131.   

crypto/asn1/x_pubkey.c:171:2: 
    169.       return ret;
    170.   
    171. >  error:
    172.       EVP_PKEY_free(ret);
    173.       return (NULL);

crypto/asn1/x_pubkey.c:172:5: 
    170.   
    171.    error:
    172. >     EVP_PKEY_free(ret);
    173.       return (NULL);
    174.   }

crypto/evp/p_lib.c:421:1: start of procedure EVP_PKEY_free()
      419.   }
      420.   
      421. > void EVP_PKEY_free(EVP_PKEY *x)
      422.   {
      423.       int i;

crypto/evp/p_lib.c:425:9: Taking true branch
      423.       int i;
      424.   
      425.       if (x == NULL)
                     ^
      426.           return;
      427.   

crypto/evp/p_lib.c:426:9: 
      424.   
      425.       if (x == NULL)
      426. >         return;
      427.   
      428.       i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY);

crypto/evp/p_lib.c:443:1: return from a call to EVP_PKEY_free
      441.       sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
      442.       OPENSSL_free(x);
      443. > }
      444.   
      445.   static void EVP_PKEY_free_it(EVP_PKEY *x)

crypto/asn1/x_pubkey.c:173:5: 
    171.    error:
    172.       EVP_PKEY_free(ret);
    173. >     return (NULL);
    174.   }
    175.   

crypto/asn1/x_pubkey.c:174:1: return from a call to X509_PUBKEY_get0
    172.       EVP_PKEY_free(ret);
    173.       return (NULL);
    174. > }
    175.   
    176.   EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)

crypto/x509/x509_cmp.c:313:1: return from a call to X509_get0_pubkey
  311.           return NULL;
  312.       return X509_PUBKEY_get0(x->cert_info.key);
  313. > }
  314.   
  315.   EVP_PKEY *X509_get_pubkey(X509 *x)

ssl/statem/statem_srvr.c:2679:5: Skipping X509_certificate_type(): empty list of specs
2677.       peer = s->session->peer;
2678.       pkey = X509_get0_pubkey(peer);
2679.       type = X509_certificate_type(peer, pkey);
            ^
2680.   
2681.       if (!(type & EVP_PKT_SIGN)) {

ssl/statem/statem_srvr.c:2681:11: Taking false branch
2679.       type = X509_certificate_type(peer, pkey);
2680.   
2681.       if (!(type & EVP_PKT_SIGN)) {
                  ^
2682.           SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY,
2683.                  SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);

ssl/statem/statem_srvr.c:2694:9: 
2692.        */
2693.   #ifndef OPENSSL_NO_GOST
2694. >     if (PACKET_remaining(pkt) == 64
2695.           && EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {
2696.           len = 64;

ssl/packet_locl.h:91:1: start of procedure PACKET_remaining()
  89.    * Returns the number of bytes remaining to be read in the PACKET
  90.    */
  91. > static ossl_inline size_t PACKET_remaining(const PACKET *pkt)
  92.   {
  93.       return pkt->remaining;

ssl/packet_locl.h:93:5: 
  91.   static ossl_inline size_t PACKET_remaining(const PACKET *pkt)
  92.   {
  93. >     return pkt->remaining;
  94.   }
  95.   

ssl/packet_locl.h:94:1: return from a call to PACKET_remaining
  92.   {
  93.       return pkt->remaining;
  94. > }
  95.   
  96.   /*

ssl/statem/statem_srvr.c:2694:9: Taking true branch
2692.        */
2693.   #ifndef OPENSSL_NO_GOST
2694.       if (PACKET_remaining(pkt) == 64
                ^
2695.           && EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {
2696.           len = 64;

ssl/statem/statem_srvr.c:2695:12: 
2693.   #ifndef OPENSSL_NO_GOST
2694.       if (PACKET_remaining(pkt) == 64
2695. >         && EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {
2696.           len = 64;
2697.       } else

crypto/evp/p_lib.c:411:1: start of procedure EVP_PKEY_id()
  409.   }
  410.   
  411. > int EVP_PKEY_id(const EVP_PKEY *pkey)
  412.   {
  413.       return pkey->type;

crypto/evp/p_lib.c:413:5: 
  411.   int EVP_PKEY_id(const EVP_PKEY *pkey)
  412.   {
  413. >     return pkey->type;
  414.   }
  415.   

MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
{
    EVP_PKEY *pkey = NULL;
    unsigned char *sig, *data;
    int al, ret = MSG_PROCESS_ERROR;
    int type = 0, j;
    unsigned int len;
    X509 *peer;
    const EVP_MD *md = NULL;
    long hdatalen = 0;
    void *hdata;
    EVP_MD_CTX *mctx = EVP_MD_CTX_new();
    if (mctx == NULL) {
        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_MALLOC_FAILURE);
        al = SSL_AD_INTERNAL_ERROR;
        goto f_err;
    }
    peer = s->session->peer;
    pkey = X509_get0_pubkey(peer);
    type = X509_certificate_type(peer, pkey);
    if (!(type & EVP_PKT_SIGN)) {
        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY,
               SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);
        al = SSL_AD_ILLEGAL_PARAMETER;
        goto f_err;
    }
#ifndef OPENSSL_NO_GOST
    if (PACKET_remaining(pkt) == 64
        && EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {
        len = 64;
    } else
#endif
    {
        if (SSL_USE_SIGALGS(s)) {
            int rv;
            if (!PACKET_get_bytes(pkt, &sig, 2)) {
                al = SSL_AD_DECODE_ERROR;
                goto f_err;
            }
            rv = tls12_check_peer_sigalg(&md, s, sig, pkey);
            if (rv == -1) {
                al = SSL_AD_INTERNAL_ERROR;
                goto f_err;
            } else if (rv == 0) {
                al = SSL_AD_DECODE_ERROR;
                goto f_err;
            }
#ifdef SSL_DEBUG
            fprintf(stderr, "USING TLSv1.2 HASH %s\n", EVP_MD_name(md));
#endif
        } else {
            int idx = ssl_cert_type(NULL, pkey);
            if (idx >= 0)
                md = s->s3->tmp.md[idx];
            if (md == NULL) {
                al = SSL_AD_INTERNAL_ERROR;
                goto f_err;
            }
        }
        if (!PACKET_get_net_2(pkt, &len)) {
            SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, SSL_R_LENGTH_MISMATCH);
            al = SSL_AD_DECODE_ERROR;
            goto f_err;
        }
    }
    j = EVP_PKEY_size(pkey);
    if (((int)len > j) || ((int)PACKET_remaining(pkt) > j)
            || (PACKET_remaining(pkt) == 0)) {
        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, SSL_R_WRONG_SIGNATURE_SIZE);
        al = SSL_AD_DECODE_ERROR;
        goto f_err;
    }
    if (!PACKET_get_bytes(pkt, &data, len)) {
        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, SSL_R_LENGTH_MISMATCH);
        al = SSL_AD_DECODE_ERROR;
        goto f_err;
    }
    hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);
    if (hdatalen <= 0) {
        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_INTERNAL_ERROR);
        al = SSL_AD_INTERNAL_ERROR;
        goto f_err;
    }
#ifdef SSL_DEBUG
    fprintf(stderr, "Using client verify alg %s\n", EVP_MD_name(md));
#endif
    if (!EVP_VerifyInit_ex(mctx, md, NULL)
        || !EVP_VerifyUpdate(mctx, hdata, hdatalen)) {
        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_EVP_LIB);
        al = SSL_AD_INTERNAL_ERROR;
        goto f_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)
            BUF_reverse(data, NULL, len);
    }
#endif
    if (s->version == SSL3_VERSION
        && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET,
                            s->session->master_key_length,
                            s->session->master_key)) {
        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_EVP_LIB);
        al = SSL_AD_INTERNAL_ERROR;
        goto f_err;
    }
    if (EVP_VerifyFinal(mctx, data, len, pkey) <= 0) {
        al = SSL_AD_DECRYPT_ERROR;
        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, SSL_R_BAD_SIGNATURE);
        goto f_err;
    }
    ret = MSG_PROCESS_CONTINUE_PROCESSING;
    if (0) {
 f_err:
        ssl3_send_alert(s, SSL3_AL_FATAL, al);
        ossl_statem_set_error(s);
    }
    BIO_free(s->s3->handshake_buffer);
    s->s3->handshake_buffer = NULL;
    EVP_MD_CTX_free(mctx);
    return ret;
}
['MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)\n{\n    EVP_PKEY *pkey = NULL;\n    unsigned char *sig, *data;\n    int al, ret = MSG_PROCESS_ERROR;\n    int type = 0, j;\n    unsigned int len;\n    X509 *peer;\n    const EVP_MD *md = NULL;\n    long hdatalen = 0;\n    void *hdata;\n    EVP_MD_CTX *mctx = EVP_MD_CTX_new();\n    if (mctx == NULL) {\n        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_MALLOC_FAILURE);\n        al = SSL_AD_INTERNAL_ERROR;\n        goto f_err;\n    }\n    peer = s->session->peer;\n    pkey = X509_get0_pubkey(peer);\n    type = X509_certificate_type(peer, pkey);\n    if (!(type & EVP_PKT_SIGN)) {\n        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY,\n               SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);\n        al = SSL_AD_ILLEGAL_PARAMETER;\n        goto f_err;\n    }\n#ifndef OPENSSL_NO_GOST\n    if (PACKET_remaining(pkt) == 64\n        && EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {\n        len = 64;\n    } else\n#endif\n    {\n        if (SSL_USE_SIGALGS(s)) {\n            int rv;\n            if (!PACKET_get_bytes(pkt, &sig, 2)) {\n                al = SSL_AD_DECODE_ERROR;\n                goto f_err;\n            }\n            rv = tls12_check_peer_sigalg(&md, s, sig, pkey);\n            if (rv == -1) {\n                al = SSL_AD_INTERNAL_ERROR;\n                goto f_err;\n            } else if (rv == 0) {\n                al = SSL_AD_DECODE_ERROR;\n                goto f_err;\n            }\n#ifdef SSL_DEBUG\n            fprintf(stderr, "USING TLSv1.2 HASH %s\\n", EVP_MD_name(md));\n#endif\n        } else {\n            int idx = ssl_cert_type(NULL, pkey);\n            if (idx >= 0)\n                md = s->s3->tmp.md[idx];\n            if (md == NULL) {\n                al = SSL_AD_INTERNAL_ERROR;\n                goto f_err;\n            }\n        }\n        if (!PACKET_get_net_2(pkt, &len)) {\n            SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, SSL_R_LENGTH_MISMATCH);\n            al = SSL_AD_DECODE_ERROR;\n            goto f_err;\n        }\n    }\n    j = EVP_PKEY_size(pkey);\n    if (((int)len > j) || ((int)PACKET_remaining(pkt) > j)\n            || (PACKET_remaining(pkt) == 0)) {\n        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, SSL_R_WRONG_SIGNATURE_SIZE);\n        al = SSL_AD_DECODE_ERROR;\n        goto f_err;\n    }\n    if (!PACKET_get_bytes(pkt, &data, len)) {\n        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, SSL_R_LENGTH_MISMATCH);\n        al = SSL_AD_DECODE_ERROR;\n        goto f_err;\n    }\n    hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);\n    if (hdatalen <= 0) {\n        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_INTERNAL_ERROR);\n        al = SSL_AD_INTERNAL_ERROR;\n        goto f_err;\n    }\n#ifdef SSL_DEBUG\n    fprintf(stderr, "Using client verify alg %s\\n", EVP_MD_name(md));\n#endif\n    if (!EVP_VerifyInit_ex(mctx, md, NULL)\n        || !EVP_VerifyUpdate(mctx, hdata, hdatalen)) {\n        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_EVP_LIB);\n        al = SSL_AD_INTERNAL_ERROR;\n        goto f_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            BUF_reverse(data, NULL, len);\n    }\n#endif\n    if (s->version == SSL3_VERSION\n        && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET,\n                            s->session->master_key_length,\n                            s->session->master_key)) {\n        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_EVP_LIB);\n        al = SSL_AD_INTERNAL_ERROR;\n        goto f_err;\n    }\n    if (EVP_VerifyFinal(mctx, data, len, pkey) <= 0) {\n        al = SSL_AD_DECRYPT_ERROR;\n        SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, SSL_R_BAD_SIGNATURE);\n        goto f_err;\n    }\n    ret = MSG_PROCESS_CONTINUE_PROCESSING;\n    if (0) {\n f_err:\n        ssl3_send_alert(s, SSL3_AL_FATAL, al);\n        ossl_statem_set_error(s);\n    }\n    BIO_free(s->s3->handshake_buffer);\n    s->s3->handshake_buffer = NULL;\n    EVP_MD_CTX_free(mctx);\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 (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    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\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}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n    EVP_PKEY *ret = NULL;\n    if (key == NULL)\n        goto error;\n    if (key->pkey != NULL)\n        return key->pkey;\n    if (key->public_key == NULL)\n        goto error;\n    if ((ret = EVP_PKEY_new()) == NULL) {\n        X509err(X509_F_X509_PUBKEY_GET0, ERR_R_MALLOC_FAILURE);\n        goto error;\n    }\n    if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) {\n        X509err(X509_F_X509_PUBKEY_GET0, X509_R_UNSUPPORTED_ALGORITHM);\n        goto error;\n    }\n    if (ret->ameth->pub_decode) {\n        if (!ret->ameth->pub_decode(ret, key)) {\n            X509err(X509_F_X509_PUBKEY_GET0, X509_R_PUBLIC_KEY_DECODE_ERROR);\n            goto error;\n        }\n    } else {\n        X509err(X509_F_X509_PUBKEY_GET0, X509_R_METHOD_NOT_SUPPORTED);\n        goto error;\n    }\n    CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY);\n    if (key->pkey) {\n        CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);\n        EVP_PKEY_free(ret);\n        ret = key->pkey;\n    } else {\n        key->pkey = ret;\n        CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);\n    }\n    return ret;\n error:\n    EVP_PKEY_free(ret);\n    return (NULL);\n}', 'void EVP_PKEY_free(EVP_PKEY *x)\n{\n    int i;\n    if (x == NULL)\n        return;\n    i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY);\n#ifdef REF_PRINT\n    REF_PRINT("EVP_PKEY", x);\n#endif\n    if (i > 0)\n        return;\n#ifdef REF_CHECK\n    if (i < 0) {\n        fprintf(stderr, "EVP_PKEY_free, bad reference count\\n");\n        abort();\n    }\n#endif\n    EVP_PKEY_free_it(x);\n    sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);\n    OPENSSL_free(x);\n}', 'int EVP_PKEY_id(const EVP_PKEY *pkey)\n{\n    return pkey->type;\n}']