ssl/d1_srvr.c:442: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 10):unsigned64 by call to `ssl3_send_server_certificate`.
Showing all 13 steps of the trace


ssl/d1_srvr.c:160:1: Parameter `s->init_buf->length`
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:442:23: Call
440.                   && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {
441.                   dtls1_start_timer(s);
442.                   ret = ssl3_send_server_certificate(s);
                             ^
443.                   if (ret <= 0)
444.                       goto end;

ssl/s3_srvr.c:3187:1: Parameter `s->init_buf->length`
  3185.   }
  3186.   
  3187. > int ssl3_send_server_certificate(SSL *s)
  3188.   {
  3189.       CERT_PKEY *cpk;

ssl/s3_srvr.c:3199:14: Call
  3197.           }
  3198.   
  3199.           if (!ssl3_output_cert_chain(s, cpk)) {
                       ^
  3200.               SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE, ERR_R_INTERNAL_ERROR);
  3201.               s->state = SSL_ST_ERR;

ssl/s3_both.c:386:1: Parameter `s->init_buf->length`
    384.   }
    385.   
    386. > unsigned long ssl3_output_cert_chain(SSL *s, CERT_PKEY *cpk)
    387.   {
    388.       unsigned char *p;

ssl/s3_both.c:391:10: Call
    389.       unsigned long l = 3 + SSL_HM_HEADER_LENGTH(s);
    390.   
    391.       if (!ssl_add_cert_chain(s, cpk, &l))
                    ^
    392.           return 0;
    393.   

ssl/ssl_cert.c:871:1: Parameter `s->init_buf->length`
      869.   
      870.   /* Add certificate chain to internal SSL BUF_MEM strcuture */
      871. > int ssl_add_cert_chain(SSL *s, CERT_PKEY *cpk, unsigned long *l)
      872.   {
      873.       BUF_MEM *buf = s->init_buf;

ssl/ssl_cert.c:881:10: Call
      879.   
      880.       /* TLSv1 sends a chain with nothing in it, instead of an alert */
      881.       if (!BUF_MEM_grow_clean(buf, 10)) {
                      ^
      882.           SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_BUF_LIB);
      883.           return 0;

crypto/buffer/buffer.c:162:1: <LHS trace>
160.   }
161.   
162. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
163.   {
164.       char *ret;

crypto/buffer/buffer.c:162:1: Parameter `len`
        160.   }
        161.   
        162. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
        163.   {
        164.       char *ret;

crypto/buffer/buffer.c:162:1: <RHS trace>
160.   }
161.   
162. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
163.   {
164.       char *ret;

crypto/buffer/buffer.c:162:1: Parameter `len`
        160.   }
        161.   
        162. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
        163.   {
        164.       char *ret;

crypto/buffer/buffer.c:168:9: Binary operation: ([0, +oo] - 10):unsigned64 by call to `ssl3_send_server_certificate` 
        166.   
        167.       if (str->length >= len) {
        168.           memset(&str->data[len], 0, str->length - len);
                       ^
        169.           str->length = len;
        170.           return (len);

size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
{
    char *ret;
    size_t n;
    if (str->length >= len) {
        memset(&str->data[len], 0, str->length - len);
        str->length = len;
        return (len);
    }
    if (str->max >= len) {
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
        return (len);
    }
    if (len > LIMIT_BEFORE_EXPANSION) {
        BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    n = (len + 3) / 3 * 4;
    if ((str->flags & BUF_MEM_FLAG_SECURE))
        ret = sec_alloc_realloc(str, n);
    else
        ret = OPENSSL_realloc_clean(str->data, str->max, n);
    if (ret == NULL) {
        BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
        len = 0;
    } else {
        str->data = ret;
        str->max = n;
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
    }
    return (len);
}
['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        if (!SSL_clear(s))\n            return -1;\n    }\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#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                    s->state = SSL_ST_ERR;\n                    goto end;\n                }\n                if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {\n                    BUF_MEM_free(buf);\n                    ret = -1;\n                    s->state = SSL_ST_ERR;\n                    goto end;\n                }\n                s->init_buf = buf;\n            }\n            if (!ssl3_setup_buffers(s)) {\n                ret = -1;\n                s->state = SSL_ST_ERR;\n                goto end;\n            }\n            s->init_num = 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                        s->state = SSL_ST_ERR;\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                DTLS_RECORD_LAYER_resync_write(&s->rlayer);\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_CHANGE_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                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_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                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            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)\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_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                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                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_CHANGE_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                    s->state = SSL_ST_ERR;\n                    return -1;\n                }\n                if (!ssl3_digest_cached_records(s, 1)) {\n                    s->state = SSL_ST_ERR;\n                    return -1;\n                }\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            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_CHANGE_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SR_CHANGE_A:\n        case SSL3_ST_SR_CHANGE_B:\n            ret = ssl3_get_change_cipher_spec(s, SSL3_ST_SR_CHANGE_A,\n                                              SSL3_ST_SR_CHANGE_B);\n            if (ret <= 0)\n                goto end;\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            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            else 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            s->init_num = 0;\n            break;\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        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                s->state = SSL_ST_ERR;\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                s->state = SSL_ST_ERR;\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_CHANGE_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            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        case SSL_ST_ERR:\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_send_server_certificate(SSL *s)\n{\n    CERT_PKEY *cpk;\n    if (s->state == SSL3_ST_SW_CERT_A) {\n        cpk = ssl_get_server_send_pkey(s);\n        if (cpk == NULL) {\n            SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE, ERR_R_INTERNAL_ERROR);\n            s->state = SSL_ST_ERR;\n            return (0);\n        }\n        if (!ssl3_output_cert_chain(s, cpk)) {\n            SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE, ERR_R_INTERNAL_ERROR);\n            s->state = SSL_ST_ERR;\n            return (0);\n        }\n        s->state = SSL3_ST_SW_CERT_B;\n    }\n    return ssl_do_write(s);\n}', 'unsigned long ssl3_output_cert_chain(SSL *s, CERT_PKEY *cpk)\n{\n    unsigned char *p;\n    unsigned long l = 3 + SSL_HM_HEADER_LENGTH(s);\n    if (!ssl_add_cert_chain(s, cpk, &l))\n        return 0;\n    l -= 3 + SSL_HM_HEADER_LENGTH(s);\n    p = ssl_handshake_start(s);\n    l2n3(l, p);\n    l += 3;\n    if (!ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE, l)) {\n        SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN, ERR_R_INTERNAL_ERROR);\n        return 0;\n    }\n    return l + SSL_HM_HEADER_LENGTH(s);\n}', 'int ssl_add_cert_chain(SSL *s, CERT_PKEY *cpk, unsigned long *l)\n{\n    BUF_MEM *buf = s->init_buf;\n    int i;\n    X509 *x;\n    STACK_OF(X509) *extra_certs;\n    X509_STORE *chain_store;\n    if (!BUF_MEM_grow_clean(buf, 10)) {\n        SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_BUF_LIB);\n        return 0;\n    }\n    if (!cpk || !cpk->x509)\n        return 1;\n    x = cpk->x509;\n    if (cpk->chain)\n        extra_certs = cpk->chain;\n    else\n        extra_certs = s->ctx->extra_certs;\n    if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)\n        chain_store = NULL;\n    else if (s->cert->chain_store)\n        chain_store = s->cert->chain_store;\n    else\n        chain_store = s->ctx->cert_store;\n    if (chain_store) {\n        X509_STORE_CTX xs_ctx;\n        if (!X509_STORE_CTX_init(&xs_ctx, chain_store, x, NULL)) {\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_X509_LIB);\n            return (0);\n        }\n        X509_verify_cert(&xs_ctx);\n        ERR_clear_error();\n        i = ssl_security_cert_chain(s, xs_ctx.chain, NULL, 0);\n        if (i != 1) {\n            X509_STORE_CTX_cleanup(&xs_ctx);\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i);\n            return 0;\n        }\n        for (i = 0; i < sk_X509_num(xs_ctx.chain); i++) {\n            x = sk_X509_value(xs_ctx.chain, i);\n            if (!ssl_add_cert_to_buf(buf, l, x)) {\n                X509_STORE_CTX_cleanup(&xs_ctx);\n                return 0;\n            }\n        }\n        X509_STORE_CTX_cleanup(&xs_ctx);\n    } else {\n        i = ssl_security_cert_chain(s, extra_certs, x, 0);\n        if (i != 1) {\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i);\n            return 0;\n        }\n        if (!ssl_add_cert_to_buf(buf, l, x))\n            return 0;\n        for (i = 0; i < sk_X509_num(extra_certs); i++) {\n            x = sk_X509_value(extra_certs, i);\n            if (!ssl_add_cert_to_buf(buf, l, x))\n                return 0;\n        }\n    }\n    return 1;\n}', 'size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)\n{\n    char *ret;\n    size_t n;\n    if (str->length >= len) {\n        memset(&str->data[len], 0, str->length - len);\n        str->length = len;\n        return (len);\n    }\n    if (str->max >= len) {\n        memset(&str->data[str->length], 0, len - str->length);\n        str->length = len;\n        return (len);\n    }\n    if (len > LIMIT_BEFORE_EXPANSION) {\n        BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    n = (len + 3) / 3 * 4;\n    if ((str->flags & BUF_MEM_FLAG_SECURE))\n        ret = sec_alloc_realloc(str, n);\n    else\n        ret = OPENSSL_realloc_clean(str->data, str->max, n);\n    if (ret == NULL) {\n        BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n        len = 0;\n    } else {\n        str->data = ret;\n        str->max = n;\n        memset(&str->data[str->length], 0, len - str->length);\n        str->length = len;\n    }\n    return (len);\n}']