ssl/d1_srvr.c:700: error: INTEGER_OVERFLOW_L2
  ([0, max(0, `s->ctx->sessions->num_items`)] - 1):unsigned64 by call to `ssl3_get_cert_verify`.
Showing all 13 steps of the trace


ssl/d1_srvr.c:160:1: Parameter `s->ctx->sessions->num_items`
158.                             dtls1_get_server_method, DTLSv1_2_enc_data)
159.   
160. > int dtls1_accept(SSL *s)
161.   {
162.       BUF_MEM *buf;

ssl/d1_srvr.c:700:19: Call
698.                   s->d1->change_cipher_spec_ok = 1;
699.               /* we should decide if we expected this one */
700.               ret = ssl3_get_cert_verify(s);
                         ^
701.               if (ret <= 0)
702.                   goto end;

ssl/s3_srvr.c:2901:1: Parameter `s->ctx->sessions->num_items`
  2899.   }
  2900.   
  2901. > int ssl3_get_cert_verify(SSL *s)
  2902.   {
  2903.       EVP_PKEY *pkey = NULL;

ssl/s3_srvr.c:3099:9: Call
  3097.       if (0) {
  3098.    f_err:
  3099.           ssl3_send_alert(s, SSL3_AL_FATAL, al);
                  ^
  3100.       }
  3101.    end:

ssl/s3_pkt.c:1760:1: Parameter `s->ctx->sessions->num_items`
    1758.   }
    1759.   
    1760. > int ssl3_send_alert(SSL *s, int level, int desc)
    1761.   {
    1762.       /* Map tls/ssl alert value to correct one */

ssl/s3_pkt.c:1771:9: Call
    1769.       /* If a fatal one, remove from cache */
    1770.       if ((level == SSL3_AL_FATAL) && (s->session != NULL))
    1771.           SSL_CTX_remove_session(s->ctx, s->session);
                    ^
    1772.   
    1773.       s->s3->alert_dispatch = 1;

ssl/ssl_sess.c:673:1: Parameter `ctx->sessions->num_items`
      671.   }
      672.   
      673. > int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
      674.   {
      675.       return remove_session_lock(ctx, c, 1);

ssl/ssl_sess.c:675:12: Call
      673.   int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
      674.   {
      675.       return remove_session_lock(ctx, c, 1);
                        ^
      676.   }
      677.   

ssl/ssl_sess.c:678:1: Parameter `ctx->sessions->num_items`
        676.   }
        677.   
        678. > static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
        679.   {
        680.       SSL_SESSION *r;

ssl/ssl_sess.c:688:17: Call
        686.           if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
        687.               ret = 1;
        688.               r = lh_SSL_SESSION_delete(ctx->sessions, c);
                               ^
        689.               SSL_SESSION_list_remove(ctx, c);
        690.           }

crypto/lhash/lhash.c:213:1: <LHS trace>
211.   }
212.   
213. > void *lh_delete(_LHASH *lh, const void *data)
214.   {
215.       unsigned long hash;

crypto/lhash/lhash.c:213:1: Parameter `lh->num_items`
          211.   }
          212.   
          213. > void *lh_delete(_LHASH *lh, const void *data)
          214.   {
          215.       unsigned long hash;

crypto/lhash/lhash.c:233:5: Binary operation: ([0, max(0, s->ctx->sessions->num_items)] - 1):unsigned64 by call to `ssl3_get_cert_verify` 
          231.       }
          232.   
          233.       lh->num_items--;
                     ^
          234.       if ((lh->num_nodes > MIN_NODES) &&
          235.           (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))

void *lh_delete(_LHASH *lh, const void *data)
{
    unsigned long hash;
    LHASH_NODE *nn, **rn;
    void *ret;
    lh->error = 0;
    rn = getrn(lh, data, &hash);
    if (*rn == NULL) {
        lh->num_no_delete++;
        return (NULL);
    } else {
        nn = *rn;
        *rn = nn->next;
        ret = nn->data;
        OPENSSL_free(nn);
        lh->num_delete++;
    }
    lh->num_items--;
    if ((lh->num_nodes > MIN_NODES) &&
        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
        contract(lh);
    return (ret);
}
['int dtls1_accept(SSL *s)\n{\n    BUF_MEM *buf;\n    unsigned long Time = (unsigned long)time(NULL);\n    void (*cb) (const SSL *ssl, int type, int val) = NULL;\n    unsigned long alg_k;\n    int ret = -1;\n    int new_state, state, skip = 0;\n    int listen;\n#ifndef OPENSSL_NO_SCTP\n    unsigned char sctpauthkey[64];\n    char labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)];\n#endif\n    RAND_add(&Time, sizeof(Time), 0);\n    ERR_clear_error();\n    clear_sys_error();\n    if (s->info_callback != NULL)\n        cb = s->info_callback;\n    else if (s->ctx->info_callback != NULL)\n        cb = s->ctx->info_callback;\n    listen = s->d1->listen;\n    s->in_handshake++;\n    if (!SSL_in_init(s) || SSL_in_before(s))\n        SSL_clear(s);\n    s->d1->listen = listen;\n#ifndef OPENSSL_NO_SCTP\n    BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,\n             s->in_handshake, NULL);\n#endif\n    if (s->cert == NULL) {\n        SSLerr(SSL_F_DTLS1_ACCEPT, SSL_R_NO_CERTIFICATE_SET);\n        return (-1);\n    }\n#ifndef OPENSSL_NO_HEARTBEATS\n    if (s->tlsext_hb_pending) {\n        dtls1_stop_timer(s);\n        s->tlsext_hb_pending = 0;\n        s->tlsext_hb_seq++;\n    }\n#endif\n    for (;;) {\n        state = s->state;\n        switch (s->state) {\n        case SSL_ST_RENEGOTIATE:\n            s->renegotiate = 1;\n        case SSL_ST_BEFORE:\n        case SSL_ST_ACCEPT:\n        case SSL_ST_BEFORE | SSL_ST_ACCEPT:\n        case SSL_ST_OK | SSL_ST_ACCEPT:\n            s->server = 1;\n            if (cb != NULL)\n                cb(s, SSL_CB_HANDSHAKE_START, 1);\n            if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00)) {\n                SSLerr(SSL_F_DTLS1_ACCEPT, ERR_R_INTERNAL_ERROR);\n                return -1;\n            }\n            s->type = SSL_ST_ACCEPT;\n            if (s->init_buf == NULL) {\n                if ((buf = BUF_MEM_new()) == NULL) {\n                    ret = -1;\n                    goto end;\n                }\n                if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {\n                    BUF_MEM_free(buf);\n                    ret = -1;\n                    goto end;\n                }\n                s->init_buf = buf;\n            }\n            if (!ssl3_setup_buffers(s)) {\n                ret = -1;\n                goto end;\n            }\n            s->init_num = 0;\n            s->d1->change_cipher_spec_ok = 0;\n            s->s3->change_cipher_spec = 0;\n            if (s->state != SSL_ST_RENEGOTIATE) {\n#ifndef OPENSSL_NO_SCTP\n                if (!BIO_dgram_is_sctp(SSL_get_wbio(s)))\n#endif\n                    if (!ssl_init_wbio_buffer(s, 1)) {\n                        ret = -1;\n                        goto end;\n                    }\n                ssl3_init_finished_mac(s);\n                s->state = SSL3_ST_SR_CLNT_HELLO_A;\n                s->ctx->stats.sess_accept++;\n            } else {\n                s->ctx->stats.sess_accept_renegotiate++;\n                s->state = SSL3_ST_SW_HELLO_REQ_A;\n            }\n            break;\n        case SSL3_ST_SW_HELLO_REQ_A:\n        case SSL3_ST_SW_HELLO_REQ_B:\n            s->shutdown = 0;\n            dtls1_clear_record_buffer(s);\n            dtls1_start_timer(s);\n            ret = ssl3_send_hello_request(s);\n            if (ret <= 0)\n                goto end;\n            s->s3->tmp.next_state = SSL3_ST_SR_CLNT_HELLO_A;\n            s->state = SSL3_ST_SW_FLUSH;\n            s->init_num = 0;\n            ssl3_init_finished_mac(s);\n            break;\n        case SSL3_ST_SW_HELLO_REQ_C:\n            s->state = SSL_ST_OK;\n            break;\n        case SSL3_ST_SR_CLNT_HELLO_A:\n        case SSL3_ST_SR_CLNT_HELLO_B:\n        case SSL3_ST_SR_CLNT_HELLO_C:\n            s->shutdown = 0;\n            ret = ssl3_get_client_hello(s);\n            if (ret <= 0)\n                goto end;\n            dtls1_stop_timer(s);\n            if (ret == 1 && (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE))\n                s->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A;\n            else\n                s->state = SSL3_ST_SW_SRVR_HELLO_A;\n            s->init_num = 0;\n            if (listen) {\n                memcpy(s->s3->write_sequence, s->s3->read_sequence,\n                       sizeof(s->s3->write_sequence));\n            }\n            if (listen && s->state == SSL3_ST_SW_SRVR_HELLO_A) {\n                ret = 2;\n                s->d1->listen = 0;\n                s->d1->handshake_read_seq = 2;\n                s->d1->handshake_write_seq = 1;\n                s->d1->next_handshake_write_seq = 1;\n                goto end;\n            }\n            break;\n        case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:\n        case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:\n            ret = dtls1_send_hello_verify_request(s);\n            if (ret <= 0)\n                goto end;\n            s->state = SSL3_ST_SW_FLUSH;\n            s->s3->tmp.next_state = SSL3_ST_SR_CLNT_HELLO_A;\n            if (s->version != DTLS1_BAD_VER)\n                ssl3_init_finished_mac(s);\n            break;\n#ifndef OPENSSL_NO_SCTP\n        case DTLS1_SCTP_ST_SR_READ_SOCK:\n            if (BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {\n                s->s3->in_read_app_data = 2;\n                s->rwstate = SSL_READING;\n                BIO_clear_retry_flags(SSL_get_rbio(s));\n                BIO_set_retry_read(SSL_get_rbio(s));\n                ret = -1;\n                goto end;\n            }\n            s->state = SSL3_ST_SR_FINISHED_A;\n            break;\n        case DTLS1_SCTP_ST_SW_WRITE_SOCK:\n            ret = BIO_dgram_sctp_wait_for_dry(SSL_get_wbio(s));\n            if (ret < 0)\n                goto end;\n            if (ret == 0) {\n                if (s->d1->next_state != SSL_ST_OK) {\n                    s->s3->in_read_app_data = 2;\n                    s->rwstate = SSL_READING;\n                    BIO_clear_retry_flags(SSL_get_rbio(s));\n                    BIO_set_retry_read(SSL_get_rbio(s));\n                    ret = -1;\n                    goto end;\n                }\n            }\n            s->state = s->d1->next_state;\n            break;\n#endif\n        case SSL3_ST_SW_SRVR_HELLO_A:\n        case SSL3_ST_SW_SRVR_HELLO_B:\n            s->renegotiate = 2;\n            dtls1_start_timer(s);\n            ret = ssl3_send_server_hello(s);\n            if (ret <= 0)\n                goto end;\n            if (s->hit) {\n#ifndef OPENSSL_NO_SCTP\n                snprintf((char *)labelbuffer, sizeof(DTLS1_SCTP_AUTH_LABEL),\n                         DTLS1_SCTP_AUTH_LABEL);\n                SSL_export_keying_material(s, sctpauthkey,\n                                           sizeof(sctpauthkey), labelbuffer,\n                                           sizeof(labelbuffer), NULL, 0, 0);\n                BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY,\n                         sizeof(sctpauthkey), sctpauthkey);\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n                if (s->tlsext_ticket_expected)\n                    s->state = SSL3_ST_SW_SESSION_TICKET_A;\n                else\n                    s->state = SSL3_ST_SW_CHANGE_A;\n#else\n                s->state = SSL3_ST_SW_CHANGE_A;\n#endif\n            } else\n                s->state = SSL3_ST_SW_CERT_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_CERT_A:\n        case SSL3_ST_SW_CERT_B:\n            if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)\n                && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {\n                dtls1_start_timer(s);\n                ret = ssl3_send_server_certificate(s);\n                if (ret <= 0)\n                    goto end;\n#ifndef OPENSSL_NO_TLSEXT\n                if (s->tlsext_status_expected)\n                    s->state = SSL3_ST_SW_CERT_STATUS_A;\n                else\n                    s->state = SSL3_ST_SW_KEY_EXCH_A;\n            } else {\n                skip = 1;\n                s->state = SSL3_ST_SW_KEY_EXCH_A;\n            }\n#else\n            } else\n                skip = 1;\n            s->state = SSL3_ST_SW_KEY_EXCH_A;\n#endif\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_KEY_EXCH_A:\n        case SSL3_ST_SW_KEY_EXCH_B:\n            alg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n            s->s3->tmp.use_rsa_tmp = 0;\n            if (0\n#ifndef OPENSSL_NO_PSK\n                || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)\n#endif\n                || (alg_k & (SSL_kDHE | SSL_kDHr | SSL_kDHd))\n                || (alg_k & SSL_kECDHE)\n                || ((alg_k & SSL_kRSA)\n                    && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL\n                        || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)\n                            && EVP_PKEY_size(s->cert->pkeys\n                                             [SSL_PKEY_RSA_ENC].privatekey) *\n                            8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)\n                        )\n                    )\n                )\n                ) {\n                dtls1_start_timer(s);\n                ret = ssl3_send_server_key_exchange(s);\n                if (ret <= 0)\n                    goto end;\n            } else\n                skip = 1;\n            s->state = SSL3_ST_SW_CERT_REQ_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_CERT_REQ_A:\n        case SSL3_ST_SW_CERT_REQ_B:\n            if (\n                   !(s->verify_mode & SSL_VERIFY_PEER) ||\n                   ((s->session->peer != NULL) &&\n                    (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||\n                   ((s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&\n                    !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||\n                   (s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5)\n                   || (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {\n                skip = 1;\n                s->s3->tmp.cert_request = 0;\n                s->state = SSL3_ST_SW_SRVR_DONE_A;\n#ifndef OPENSSL_NO_SCTP\n                if (BIO_dgram_is_sctp(SSL_get_wbio(s))) {\n                    s->d1->next_state = SSL3_ST_SW_SRVR_DONE_A;\n                    s->state = DTLS1_SCTP_ST_SW_WRITE_SOCK;\n                }\n#endif\n            } else {\n                s->s3->tmp.cert_request = 1;\n                dtls1_start_timer(s);\n                ret = ssl3_send_certificate_request(s);\n                if (ret <= 0)\n                    goto end;\n#ifndef NETSCAPE_HANG_BUG\n                s->state = SSL3_ST_SW_SRVR_DONE_A;\n# ifndef OPENSSL_NO_SCTP\n                if (BIO_dgram_is_sctp(SSL_get_wbio(s))) {\n                    s->d1->next_state = SSL3_ST_SW_SRVR_DONE_A;\n                    s->state = DTLS1_SCTP_ST_SW_WRITE_SOCK;\n                }\n# endif\n#else\n                s->state = SSL3_ST_SW_FLUSH;\n                s->s3->tmp.next_state = SSL3_ST_SR_CERT_A;\n# ifndef OPENSSL_NO_SCTP\n                if (BIO_dgram_is_sctp(SSL_get_wbio(s))) {\n                    s->d1->next_state = s->s3->tmp.next_state;\n                    s->s3->tmp.next_state = DTLS1_SCTP_ST_SW_WRITE_SOCK;\n                }\n# endif\n#endif\n                s->init_num = 0;\n            }\n            break;\n        case SSL3_ST_SW_SRVR_DONE_A:\n        case SSL3_ST_SW_SRVR_DONE_B:\n            dtls1_start_timer(s);\n            ret = ssl3_send_server_done(s);\n            if (ret <= 0)\n                goto end;\n            s->s3->tmp.next_state = SSL3_ST_SR_CERT_A;\n            s->state = SSL3_ST_SW_FLUSH;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_FLUSH:\n            s->rwstate = SSL_WRITING;\n            if (BIO_flush(s->wbio) <= 0) {\n                if (!BIO_should_retry(s->wbio)) {\n                    s->rwstate = SSL_NOTHING;\n                    s->state = s->s3->tmp.next_state;\n                }\n                ret = -1;\n                goto end;\n            }\n            s->rwstate = SSL_NOTHING;\n            s->state = s->s3->tmp.next_state;\n            break;\n        case SSL3_ST_SR_CERT_A:\n        case SSL3_ST_SR_CERT_B:\n            if (s->s3->tmp.cert_request) {\n                ret = ssl3_get_client_certificate(s);\n                if (ret <= 0)\n                    goto end;\n            }\n            s->init_num = 0;\n            s->state = SSL3_ST_SR_KEY_EXCH_A;\n            break;\n        case SSL3_ST_SR_KEY_EXCH_A:\n        case SSL3_ST_SR_KEY_EXCH_B:\n            ret = ssl3_get_client_key_exchange(s);\n            if (ret <= 0)\n                goto end;\n#ifndef OPENSSL_NO_SCTP\n            snprintf((char *)labelbuffer, sizeof(DTLS1_SCTP_AUTH_LABEL),\n                     DTLS1_SCTP_AUTH_LABEL);\n            SSL_export_keying_material(s, sctpauthkey,\n                                       sizeof(sctpauthkey), labelbuffer,\n                                       sizeof(labelbuffer), NULL, 0, 0);\n            BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY,\n                     sizeof(sctpauthkey), sctpauthkey);\n#endif\n            s->state = SSL3_ST_SR_CERT_VRFY_A;\n            s->init_num = 0;\n            if (ret == 2) {\n                s->state = SSL3_ST_SR_FINISHED_A;\n                s->init_num = 0;\n            } else if (SSL_USE_SIGALGS(s)) {\n                s->state = SSL3_ST_SR_CERT_VRFY_A;\n                s->init_num = 0;\n                if (!s->session->peer)\n                    break;\n                if (!s->s3->handshake_buffer) {\n                    SSLerr(SSL_F_DTLS1_ACCEPT, ERR_R_INTERNAL_ERROR);\n                    return -1;\n                }\n                s->s3->flags |= TLS1_FLAGS_KEEP_HANDSHAKE;\n                if (!ssl3_digest_cached_records(s))\n                    return -1;\n            } else {\n                s->state = SSL3_ST_SR_CERT_VRFY_A;\n                s->init_num = 0;\n                s->method->ssl3_enc->cert_verify_mac(s,\n                                                     NID_md5,\n                                                     &(s->s3->\n                                                       tmp.cert_verify_md\n                                                       [0]));\n                s->method->ssl3_enc->cert_verify_mac(s, NID_sha1,\n                                                     &(s->s3->\n                                                       tmp.cert_verify_md\n                                                       [MD5_DIGEST_LENGTH]));\n            }\n            break;\n        case SSL3_ST_SR_CERT_VRFY_A:\n        case SSL3_ST_SR_CERT_VRFY_B:\n            if (!s->s3->change_cipher_spec)\n                s->d1->change_cipher_spec_ok = 1;\n            ret = ssl3_get_cert_verify(s);\n            if (ret <= 0)\n                goto end;\n#ifndef OPENSSL_NO_SCTP\n            if (BIO_dgram_is_sctp(SSL_get_wbio(s)) &&\n                state == SSL_ST_RENEGOTIATE)\n                s->state = DTLS1_SCTP_ST_SR_READ_SOCK;\n            else\n#endif\n                s->state = SSL3_ST_SR_FINISHED_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SR_FINISHED_A:\n        case SSL3_ST_SR_FINISHED_B:\n            if (!s->s3->change_cipher_spec)\n                s->d1->change_cipher_spec_ok = 1;\n            ret = ssl3_get_finished(s, SSL3_ST_SR_FINISHED_A,\n                                    SSL3_ST_SR_FINISHED_B);\n            if (ret <= 0)\n                goto end;\n            dtls1_stop_timer(s);\n            if (s->hit)\n                s->state = SSL_ST_OK;\n#ifndef OPENSSL_NO_TLSEXT\n            else if (s->tlsext_ticket_expected)\n                s->state = SSL3_ST_SW_SESSION_TICKET_A;\n#endif\n            else\n                s->state = SSL3_ST_SW_CHANGE_A;\n            s->init_num = 0;\n            break;\n#ifndef OPENSSL_NO_TLSEXT\n        case SSL3_ST_SW_SESSION_TICKET_A:\n        case SSL3_ST_SW_SESSION_TICKET_B:\n            ret = ssl3_send_newsession_ticket(s);\n            if (ret <= 0)\n                goto end;\n            s->state = SSL3_ST_SW_CHANGE_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_CERT_STATUS_A:\n        case SSL3_ST_SW_CERT_STATUS_B:\n            ret = ssl3_send_cert_status(s);\n            if (ret <= 0)\n                goto end;\n            s->state = SSL3_ST_SW_KEY_EXCH_A;\n            s->init_num = 0;\n            break;\n#endif\n        case SSL3_ST_SW_CHANGE_A:\n        case SSL3_ST_SW_CHANGE_B:\n            s->session->cipher = s->s3->tmp.new_cipher;\n            if (!s->method->ssl3_enc->setup_key_block(s)) {\n                ret = -1;\n                goto end;\n            }\n            ret = dtls1_send_change_cipher_spec(s,\n                                                SSL3_ST_SW_CHANGE_A,\n                                                SSL3_ST_SW_CHANGE_B);\n            if (ret <= 0)\n                goto end;\n#ifndef OPENSSL_NO_SCTP\n            if (!s->hit) {\n                BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY,\n                         0, NULL);\n            }\n#endif\n            s->state = SSL3_ST_SW_FINISHED_A;\n            s->init_num = 0;\n            if (!s->method->ssl3_enc->change_cipher_state(s,\n                                                          SSL3_CHANGE_CIPHER_SERVER_WRITE))\n            {\n                ret = -1;\n                goto end;\n            }\n            dtls1_reset_seq_numbers(s, SSL3_CC_WRITE);\n            break;\n        case SSL3_ST_SW_FINISHED_A:\n        case SSL3_ST_SW_FINISHED_B:\n            ret = ssl3_send_finished(s,\n                                     SSL3_ST_SW_FINISHED_A,\n                                     SSL3_ST_SW_FINISHED_B,\n                                     s->method->\n                                     ssl3_enc->server_finished_label,\n                                     s->method->\n                                     ssl3_enc->server_finished_label_len);\n            if (ret <= 0)\n                goto end;\n            s->state = SSL3_ST_SW_FLUSH;\n            if (s->hit) {\n                s->s3->tmp.next_state = SSL3_ST_SR_FINISHED_A;\n#ifndef OPENSSL_NO_SCTP\n                BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY,\n                         0, NULL);\n#endif\n            } else {\n                s->s3->tmp.next_state = SSL_ST_OK;\n#ifndef OPENSSL_NO_SCTP\n                if (BIO_dgram_is_sctp(SSL_get_wbio(s))) {\n                    s->d1->next_state = s->s3->tmp.next_state;\n                    s->s3->tmp.next_state = DTLS1_SCTP_ST_SW_WRITE_SOCK;\n                }\n#endif\n            }\n            s->init_num = 0;\n            break;\n        case SSL_ST_OK:\n            ssl3_cleanup_key_block(s);\n#if 0\n            BUF_MEM_free(s->init_buf);\n            s->init_buf = NULL;\n#endif\n            ssl_free_wbio_buffer(s);\n            s->init_num = 0;\n            if (s->renegotiate == 2) {\n                s->renegotiate = 0;\n                s->new_session = 0;\n                ssl_update_cache(s, SSL_SESS_CACHE_SERVER);\n                s->ctx->stats.sess_accept_good++;\n                s->handshake_func = dtls1_accept;\n                if (cb != NULL)\n                    cb(s, SSL_CB_HANDSHAKE_DONE, 1);\n            }\n            ret = 1;\n            s->d1->handshake_read_seq = 0;\n            s->d1->handshake_write_seq = 0;\n            s->d1->next_handshake_write_seq = 0;\n            goto end;\n        default:\n            SSLerr(SSL_F_DTLS1_ACCEPT, SSL_R_UNKNOWN_STATE);\n            ret = -1;\n            goto end;\n        }\n        if (!s->s3->tmp.reuse_message && !skip) {\n            if (s->debug) {\n                if ((ret = BIO_flush(s->wbio)) <= 0)\n                    goto end;\n            }\n            if ((cb != NULL) && (s->state != state)) {\n                new_state = s->state;\n                s->state = state;\n                cb(s, SSL_CB_ACCEPT_LOOP, 1);\n                s->state = new_state;\n            }\n        }\n        skip = 0;\n    }\n end:\n    s->in_handshake--;\n#ifndef OPENSSL_NO_SCTP\n    BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,\n             s->in_handshake, NULL);\n#endif\n    if (cb != NULL)\n        cb(s, SSL_CB_ACCEPT_EXIT, ret);\n    return (ret);\n}', 'int ssl3_get_cert_verify(SSL *s)\n{\n    EVP_PKEY *pkey = NULL;\n    unsigned char *p;\n    int al, ok, ret = 0;\n    long n;\n    int type = 0, i, j;\n    X509 *peer;\n    const EVP_MD *md = NULL;\n    EVP_MD_CTX mctx;\n    EVP_MD_CTX_init(&mctx);\n    n = s->method->ssl_get_message(s,\n                                   SSL3_ST_SR_CERT_VRFY_A,\n                                   SSL3_ST_SR_CERT_VRFY_B,\n                                   -1, SSL3_RT_MAX_PLAIN_LENGTH, &ok);\n    if (!ok)\n        return ((int)n);\n    if (s->session->peer != NULL) {\n        peer = s->session->peer;\n        pkey = X509_get_pubkey(peer);\n        type = X509_certificate_type(peer, pkey);\n    } else {\n        peer = NULL;\n        pkey = NULL;\n    }\n    if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY) {\n        s->s3->tmp.reuse_message = 1;\n        if (peer != NULL) {\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_MISSING_VERIFY_MESSAGE);\n            goto f_err;\n        }\n        ret = 1;\n        goto end;\n    }\n    if (peer == NULL) {\n        SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_NO_CLIENT_CERT_RECEIVED);\n        al = SSL_AD_UNEXPECTED_MESSAGE;\n        goto f_err;\n    }\n    if (!(type & EVP_PKT_SIGN)) {\n        SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,\n               SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);\n        al = SSL_AD_ILLEGAL_PARAMETER;\n        goto f_err;\n    }\n    if (s->s3->change_cipher_spec) {\n        SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_CCS_RECEIVED_EARLY);\n        al = SSL_AD_UNEXPECTED_MESSAGE;\n        goto f_err;\n    }\n    p = (unsigned char *)s->init_msg;\n    if (n == 64 && (pkey->type == NID_id_GostR3410_94 ||\n                    pkey->type == NID_id_GostR3410_2001)) {\n        i = 64;\n    } else {\n        if (SSL_USE_SIGALGS(s)) {\n            int rv = tls12_check_peer_sigalg(&md, s, p, 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            p += 2;\n            n -= 2;\n        }\n        n2s(p, i);\n        n -= 2;\n        if (i > n) {\n            SSLerr(SSL_F_SSL3_GET_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 ((i > j) || (n > j) || (n <= 0)) {\n        SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_WRONG_SIGNATURE_SIZE);\n        al = SSL_AD_DECODE_ERROR;\n        goto f_err;\n    }\n    if (SSL_USE_SIGALGS(s)) {\n        long hdatalen = 0;\n        void *hdata;\n        hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);\n        if (hdatalen <= 0) {\n            SSLerr(SSL_F_SSL3_GET_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 TLS 1.2 with client verify alg %s\\n",\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_SSL3_GET_CERT_VERIFY, ERR_R_EVP_LIB);\n            al = SSL_AD_INTERNAL_ERROR;\n            goto f_err;\n        }\n        if (EVP_VerifyFinal(&mctx, p, i, pkey) <= 0) {\n            al = SSL_AD_DECRYPT_ERROR;\n            SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_BAD_SIGNATURE);\n            goto f_err;\n        }\n    } else\n#ifndef OPENSSL_NO_RSA\n    if (pkey->type == EVP_PKEY_RSA) {\n        i = RSA_verify(NID_md5_sha1, s->s3->tmp.cert_verify_md,\n                       MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH, p, i,\n                       pkey->pkey.rsa);\n        if (i < 0) {\n            al = SSL_AD_DECRYPT_ERROR;\n            SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_BAD_RSA_DECRYPT);\n            goto f_err;\n        }\n        if (i == 0) {\n            al = SSL_AD_DECRYPT_ERROR;\n            SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_BAD_RSA_SIGNATURE);\n            goto f_err;\n        }\n    } else\n#endif\n#ifndef OPENSSL_NO_DSA\n    if (pkey->type == EVP_PKEY_DSA) {\n        j = DSA_verify(pkey->save_type,\n                       &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]),\n                       SHA_DIGEST_LENGTH, p, i, pkey->pkey.dsa);\n        if (j <= 0) {\n            al = SSL_AD_DECRYPT_ERROR;\n            SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_BAD_DSA_SIGNATURE);\n            goto f_err;\n        }\n    } else\n#endif\n#ifndef OPENSSL_NO_ECDSA\n    if (pkey->type == EVP_PKEY_EC) {\n        j = ECDSA_verify(pkey->save_type,\n                         &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]),\n                         SHA_DIGEST_LENGTH, p, i, pkey->pkey.ec);\n        if (j <= 0) {\n            al = SSL_AD_DECRYPT_ERROR;\n            SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_BAD_ECDSA_SIGNATURE);\n            goto f_err;\n        }\n    } else\n#endif\n    if (pkey->type == NID_id_GostR3410_94\n            || pkey->type == NID_id_GostR3410_2001) {\n        unsigned char signature[64];\n        int idx;\n        EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(pkey, NULL);\n        EVP_PKEY_verify_init(pctx);\n        if (i != 64) {\n            fprintf(stderr, "GOST signature length is %d", i);\n        }\n        for (idx = 0; idx < 64; idx++) {\n            signature[63 - idx] = p[idx];\n        }\n        j = EVP_PKEY_verify(pctx, signature, 64, s->s3->tmp.cert_verify_md,\n                            32);\n        EVP_PKEY_CTX_free(pctx);\n        if (j <= 0) {\n            al = SSL_AD_DECRYPT_ERROR;\n            SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, SSL_R_BAD_ECDSA_SIGNATURE);\n            goto f_err;\n        }\n    } else {\n        SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, ERR_R_INTERNAL_ERROR);\n        al = SSL_AD_UNSUPPORTED_CERTIFICATE;\n        goto f_err;\n    }\n    ret = 1;\n    if (0) {\n f_err:\n        ssl3_send_alert(s, SSL3_AL_FATAL, al);\n    }\n end:\n    if (s->s3->handshake_buffer) {\n        BIO_free(s->s3->handshake_buffer);\n        s->s3->handshake_buffer = NULL;\n        s->s3->flags &= ~TLS1_FLAGS_KEEP_HANDSHAKE;\n    }\n    EVP_MD_CTX_cleanup(&mctx);\n    EVP_PKEY_free(pkey);\n    return (ret);\n}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n{\n    desc = s->method->ssl3_enc->alert_value(desc);\n    if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n        desc = SSL_AD_HANDSHAKE_FAILURE;\n    if (desc < 0)\n        return -1;\n    if ((level == SSL3_AL_FATAL) && (s->session != NULL))\n        SSL_CTX_remove_session(s->ctx, s->session);\n    s->s3->alert_dispatch = 1;\n    s->s3->send_alert[0] = level;\n    s->s3->send_alert[1] = desc;\n    if (s->s3->wbuf.left == 0)\n        return s->method->ssl_dispatch_alert(s);\n    return -1;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n    return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n    SSL_SESSION *r;\n    int ret = 0;\n    if ((c != NULL) && (c->session_id_length != 0)) {\n        if (lck)\n            CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n        if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n            ret = 1;\n            r = lh_SSL_SESSION_delete(ctx->sessions, c);\n            SSL_SESSION_list_remove(ctx, c);\n        }\n        if (lck)\n            CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n        if (ret) {\n            r->not_resumable = 1;\n            if (ctx->remove_session_cb != NULL)\n                ctx->remove_session_cb(ctx, r);\n            SSL_SESSION_free(r);\n        }\n    } else\n        ret = 0;\n    return (ret);\n}', 'void *lh_delete(_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    LHASH_NODE *nn, **rn;\n    void *ret;\n    lh->error = 0;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        lh->num_no_delete++;\n        return (NULL);\n    } else {\n        nn = *rn;\n        *rn = nn->next;\n        ret = nn->data;\n        OPENSSL_free(nn);\n        lh->num_delete++;\n    }\n    lh->num_items--;\n    if ((lh->num_nodes > MIN_NODES) &&\n        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n        contract(lh);\n    return (ret);\n}']