ssl/statem/statem_srvr.c:2991: error: NULL_DEREFERENCE
  pointer `pkey` last assigned on line 2976 could be null and is dereferenced at line 2991, column 40.
Showing all 24 steps of the trace


ssl/statem/statem_srvr.c:2960:1: start of procedure tls_process_cert_verify()
2958.   }
2959.   
2960. > MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
2961.   {
2962.       EVP_PKEY *pkey = NULL;

ssl/statem/statem_srvr.c:2962:5: 
2960.   MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
2961.   {
2962. >     EVP_PKEY *pkey = NULL;
2963.       unsigned char *sig, *data;
2964.       int al, ret = MSG_PROCESS_ERROR;

ssl/statem/statem_srvr.c:2964:5: 
2962.       EVP_PKEY *pkey = NULL;
2963.       unsigned char *sig, *data;
2964. >     int al, ret = MSG_PROCESS_ERROR;
2965.       int type = 0, j;
2966.       unsigned int len;

ssl/statem/statem_srvr.c:2965:5: 
2963.       unsigned char *sig, *data;
2964.       int al, ret = MSG_PROCESS_ERROR;
2965. >     int type = 0, j;
2966.       unsigned int len;
2967.       X509 *peer;

ssl/statem/statem_srvr.c:2968:5: 
2966.       unsigned int len;
2967.       X509 *peer;
2968. >     const EVP_MD *md = NULL;
2969.       long hdatalen = 0;
2970.       void *hdata;

ssl/statem/statem_srvr.c:2969:5: 
2967.       X509 *peer;
2968.       const EVP_MD *md = NULL;
2969. >     long hdatalen = 0;
2970.       void *hdata;
2971.   

ssl/statem/statem_srvr.c:2973:5: 
2971.   
2972.       EVP_MD_CTX mctx;
2973. >     EVP_MD_CTX_init(&mctx);
2974.   
2975.       peer = s->session->peer;

crypto/evp/digest.c:120:1: start of procedure EVP_MD_CTX_init()
  118.   #endif
  119.   
  120. > void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
  121.   {
  122.       memset(ctx, 0, sizeof(*ctx));

crypto/evp/digest.c:122:5: 
  120.   void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
  121.   {
  122. >     memset(ctx, 0, sizeof(*ctx));
  123.   }
  124.   

crypto/evp/digest.c:123:1: return from a call to EVP_MD_CTX_init
  121.   {
  122.       memset(ctx, 0, sizeof(*ctx));
  123. > }
  124.   
  125.   EVP_MD_CTX *EVP_MD_CTX_create(void)

ssl/statem/statem_srvr.c:2975:5: 
2973.       EVP_MD_CTX_init(&mctx);
2974.   
2975. >     peer = s->session->peer;
2976.       pkey = X509_get_pubkey(peer);
2977.       type = X509_certificate_type(peer, pkey);

ssl/statem/statem_srvr.c:2976:5: 
2974.   
2975.       peer = s->session->peer;
2976. >     pkey = X509_get_pubkey(peer);
2977.       type = X509_certificate_type(peer, pkey);
2978.   

crypto/x509/x509_cmp.c:305:1: start of procedure X509_get_pubkey()
  303.   }
  304.   
  305. > EVP_PKEY *X509_get_pubkey(X509 *x)
  306.   {
  307.       if (x == NULL)

crypto/x509/x509_cmp.c:307:9: Taking true branch
  305.   EVP_PKEY *X509_get_pubkey(X509 *x)
  306.   {
  307.       if (x == NULL)
                 ^
  308.           return (NULL);
  309.       return (X509_PUBKEY_get(x->cert_info.key));

crypto/x509/x509_cmp.c:308:9: 
  306.   {
  307.       if (x == NULL)
  308. >         return (NULL);
  309.       return (X509_PUBKEY_get(x->cert_info.key));
  310.   }

crypto/x509/x509_cmp.c:310:1: return from a call to X509_get_pubkey
  308.           return (NULL);
  309.       return (X509_PUBKEY_get(x->cert_info.key));
  310. > }
  311.   
  312.   ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x)

ssl/statem/statem_srvr.c:2977:5: Skipping X509_certificate_type(): empty list of specs
2975.       peer = s->session->peer;
2976.       pkey = X509_get_pubkey(peer);
2977.       type = X509_certificate_type(peer, pkey);
            ^
2978.   
2979.       if (!(type & EVP_PKT_SIGN)) {

ssl/statem/statem_srvr.c:2979:11: Taking false branch
2977.       type = X509_certificate_type(peer, pkey);
2978.   
2979.       if (!(type & EVP_PKT_SIGN)) {
                  ^
2980.           SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY,
2981.                  SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);

ssl/statem/statem_srvr.c:2991:9: 
2989.        * length field (CryptoPro implementations at least till CSP 4.0)
2990.        */
2991. >     if (PACKET_remaining(pkt) == 64 && pkey->type == NID_id_GostR3410_2001) {
2992.           len = 64;
2993.       } else {

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

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

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

ssl/statem/statem_srvr.c:2991:9: Taking true branch
2989.        * length field (CryptoPro implementations at least till CSP 4.0)
2990.        */
2991.       if (PACKET_remaining(pkt) == 64 && pkey->type == NID_id_GostR3410_2001) {
                ^
2992.           len = 64;
2993.       } else {

ssl/statem/statem_srvr.c:2991:40: 
2989.        * length field (CryptoPro implementations at least till CSP 4.0)
2990.        */
2991. >     if (PACKET_remaining(pkt) == 64 && pkey->type == NID_id_GostR3410_2001) {
2992.           len = 64;
2993.       } else {

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_init(&mctx);
    peer = s->session->peer;
    pkey = X509_get_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;
    }
    if (PACKET_remaining(pkt) == 64 && pkey->type == NID_id_GostR3410_2001) {
        len = 64;
    } else {
        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 if (pkey->type == EVP_PKEY_RSA) {
            md = EVP_md5_sha1();
        } else {
            md = EVP_sha1();
        }
        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;
    }
    if (pkey->type == NID_id_GostR3410_2001
            || pkey->type == NID_id_GostR3410_2012_256
            || pkey->type == NID_id_GostR3410_2012_512) {
        unsigned int j1, j2;
        for (j1 = len - 1, j2 = 0; j2 < len/2; j2++, j1--) {
            char c = data[j2];
            data[j2] = data[j1];
            data[j1] = c;
        }
    }
    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_cleanup(&mctx);
    EVP_PKEY_free(pkey);
    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;\n    EVP_MD_CTX_init(&mctx);\n    peer = s->session->peer;\n    pkey = X509_get_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    if (PACKET_remaining(pkt) == 64 && pkey->type == NID_id_GostR3410_2001) {\n        len = 64;\n    } else {\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 if (pkey->type == EVP_PKEY_RSA) {\n            md = EVP_md5_sha1();\n        } else {\n            md = EVP_sha1();\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    if (pkey->type == NID_id_GostR3410_2001\n            || pkey->type == NID_id_GostR3410_2012_256\n            || pkey->type == NID_id_GostR3410_2012_512) {\n        unsigned int j1, j2;\n        for (j1 = len - 1, j2 = 0; j2 < len/2; j2++, j1--) {\n            char c = data[j2];\n            data[j2] = data[j1];\n            data[j1] = c;\n        }\n    }\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_cleanup(&mctx);\n    EVP_PKEY_free(pkey);\n    return ret;\n}', 'void EVP_MD_CTX_init(EVP_MD_CTX *ctx)\n{\n    memset(ctx, 0, sizeof(*ctx));\n}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n{\n    if (x == NULL)\n        return (NULL);\n    return (X509_PUBKEY_get(x->cert_info.key));\n}', 'static inline size_t PACKET_remaining(const PACKET *pkt)\n{\n    return pkt->remaining;\n}']