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


ssl/statem/statem_srvr.c:2650:1: start of procedure tls_process_cert_verify()
2648.   }
2649.   
2650. > MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
2651.   {
2652.       EVP_PKEY *pkey = NULL;

ssl/statem/statem_srvr.c:2652:5: 
2650.   MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
2651.   {
2652. >     EVP_PKEY *pkey = NULL;
2653.       const unsigned char *sig, *data;
2654.       unsigned char *gost_data = NULL;

ssl/statem/statem_srvr.c:2654:5: 
2652.       EVP_PKEY *pkey = NULL;
2653.       const unsigned char *sig, *data;
2654. >     unsigned char *gost_data = NULL;
2655.       int al, ret = MSG_PROCESS_ERROR;
2656.       int type = 0, j;

ssl/statem/statem_srvr.c:2655:5: 
2653.       const unsigned char *sig, *data;
2654.       unsigned char *gost_data = NULL;
2655. >     int al, ret = MSG_PROCESS_ERROR;
2656.       int type = 0, j;
2657.       unsigned int len;

ssl/statem/statem_srvr.c:2656:5: 
2654.       unsigned char *gost_data = NULL;
2655.       int al, ret = MSG_PROCESS_ERROR;
2656. >     int type = 0, j;
2657.       unsigned int len;
2658.       X509 *peer;

ssl/statem/statem_srvr.c:2659:5: 
2657.       unsigned int len;
2658.       X509 *peer;
2659. >     const EVP_MD *md = NULL;
2660.       long hdatalen = 0;
2661.       void *hdata;

ssl/statem/statem_srvr.c:2660:5: 
2658.       X509 *peer;
2659.       const EVP_MD *md = NULL;
2660. >     long hdatalen = 0;
2661.       void *hdata;
2662.   

ssl/statem/statem_srvr.c:2663:5: 
2661.       void *hdata;
2662.   
2663. >     EVP_MD_CTX *mctx = EVP_MD_CTX_new();
2664.   
2665.       if (mctx == NULL) {

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

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

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

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

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

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

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      124.           return malloc_impl(num, file, line);
      125.   

crypto/mem.c:126:9: Taking false branch
      124.           return malloc_impl(num, file, line);
      125.   
      126.       if (num <= 0)
                     ^
      127.           return NULL;
      128.   

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

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

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

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

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

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

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

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

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

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

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

ssl/statem/statem_srvr.c:2665:9: Taking false branch
2663.       EVP_MD_CTX *mctx = EVP_MD_CTX_new();
2664.   
2665.       if (mctx == NULL) {
                ^
2666.           SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_MALLOC_FAILURE);
2667.           al = SSL_AD_INTERNAL_ERROR;

ssl/statem/statem_srvr.c:2671:5: 
2669.       }
2670.   
2671. >     peer = s->session->peer;
2672.       pkey = X509_get0_pubkey(peer);
2673.       type = X509_certificate_type(peer, pkey);

ssl/statem/statem_srvr.c:2672:5: 
2670.   
2671.       peer = s->session->peer;
2672. >     pkey = X509_get0_pubkey(peer);
2673.       type = X509_certificate_type(peer, pkey);
2674.   

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

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

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

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

ssl/statem/statem_srvr.c:2673:5: Skipping X509_certificate_type(): empty list of specs
2671.       peer = s->session->peer;
2672.       pkey = X509_get0_pubkey(peer);
2673.       type = X509_certificate_type(peer, pkey);
            ^
2674.   
2675.       if (!(type & EVP_PKT_SIGN)) {

ssl/statem/statem_srvr.c:2675:11: Taking false branch
2673.       type = X509_certificate_type(peer, pkey);
2674.   
2675.       if (!(type & EVP_PKT_SIGN)) {
                  ^
2676.           SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY,
2677.                  SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);

ssl/statem/statem_srvr.c:2688:9: 
2686.        */
2687.   #ifndef OPENSSL_NO_GOST
2688. >     if (PACKET_remaining(pkt) == 64
2689.           && EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {
2690.           len = 64;

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

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

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

ssl/statem/statem_srvr.c:2688:9: Taking true branch
2686.        */
2687.   #ifndef OPENSSL_NO_GOST
2688.       if (PACKET_remaining(pkt) == 64
                ^
2689.           && EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {
2690.           len = 64;

ssl/statem/statem_srvr.c:2689:12: 
2687.   #ifndef OPENSSL_NO_GOST
2688.       if (PACKET_remaining(pkt) == 64
2689. >         && EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) {
2690.           len = 64;
2691.       } else

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

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

MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
{
    EVP_PKEY *pkey = NULL;
    const unsigned char *sig, *data;
    unsigned char *gost_data = NULL;
    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) {
            if ((gost_data = OPENSSL_malloc(len)) == NULL) {
                SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_MALLOC_FAILURE);
                al = SSL_AD_INTERNAL_ERROR;
                goto f_err;
            }
            BUF_reverse(gost_data, data, len);
            data = gost_data;
        }
    }
#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);
    OPENSSL_free(gost_data);
    return ret;
}
['MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)\n{\n    EVP_PKEY *pkey = NULL;\n    const unsigned char *sig, *data;\n    unsigned char *gost_data = NULL;\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            if ((gost_data = OPENSSL_malloc(len)) == 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            BUF_reverse(gost_data, data, len);\n            data = gost_data;\n        }\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    OPENSSL_free(gost_data);\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 (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (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}', 'int EVP_PKEY_id(const EVP_PKEY *pkey)\n{\n    return pkey->type;\n}']