X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=ssl%2Fstatem%2Fstatem.c;h=a1da2a4418d112eac0f88beb28b6428065bbc0f6;hb=5abeaf3596210d8cc0be1edf7a0a772b7e2c7e6f;hp=27dd5d62e56b5c61a6ae2f21988ea0002af38650;hpb=f3b3d7f0033080f86ede5a53e8af2fb313091b5a;p=oweals%2Fopenssl.git diff --git a/ssl/statem/statem.c b/ssl/statem/statem.c index 27dd5d62e5..a1da2a4418 100644 --- a/ssl/statem/statem.c +++ b/ssl/statem/statem.c @@ -251,20 +251,6 @@ static int state_machine(SSL *s, int server) } #endif -#ifndef OPENSSL_NO_HEARTBEATS - /* - * If we're awaiting a HeartbeatResponse, pretend we already got and - * don't await it anymore, because Heartbeats don't make sense during - * handshakes anyway. - */ - if (s->tlsext_hb_pending) { - if (SSL_IS_DTLS(s)) - dtls1_stop_timer(s); - s->tlsext_hb_pending = 0; - s->tlsext_hb_seq++; - } -#endif - /* Initialise state machine */ if (st->state == MSG_FLOW_RENEGOTIATE) { @@ -445,6 +431,21 @@ static void init_read_state_machine(SSL *s) st->read_state = READ_STATE_HEADER; } +static int grow_init_buf(SSL *s, size_t size) { + + size_t msg_offset = (char *)s->init_msg - s->init_buf->data; + + if (!BUF_MEM_grow_clean(s->init_buf, (int)size)) + return 0; + + if (size < msg_offset) + return 0; + + s->init_msg = s->init_buf->data + msg_offset; + + return 1; +} + /* * This function implements the sub-state machine when the message flow is in * MSG_FLOW_READING. The valid sub-states and transitions are: @@ -475,12 +476,12 @@ static SUB_STATE_RETURN read_state_machine(SSL *s) { OSSL_STATEM *st = &s->statem; int ret, mt; - unsigned long len = 0; + size_t len = 0; int (*transition) (SSL *s, int mt); PACKET pkt; MSG_PROCESS_RETURN(*process_message) (SSL *s, PACKET *pkt); WORK_STATE(*post_process_message) (SSL *s, WORK_STATE wst); - unsigned long (*max_message_size) (SSL *s); + size_t (*max_message_size) (SSL *s); void (*cb) (const SSL *ssl, int type, int val) = NULL; cb = get_callback(s); @@ -545,9 +546,8 @@ static SUB_STATE_RETURN read_state_machine(SSL *s) /* dtls_get_message already did this */ if (!SSL_IS_DTLS(s) && s->s3->tmp.message_size > 0 - && !BUF_MEM_grow_clean(s->init_buf, - (int)s->s3->tmp.message_size - + SSL3_HM_HEADER_LENGTH)) { + && !grow_init_buf(s, s->s3->tmp.message_size + + SSL3_HM_HEADER_LENGTH)) { ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_BUF_LIB); return SUB_STATE_ERROR; @@ -694,8 +694,13 @@ static SUB_STATE_RETURN write_state_machine(SSL *s) WRITE_TRAN(*transition) (SSL *s); WORK_STATE(*pre_work) (SSL *s, WORK_STATE wst); WORK_STATE(*post_work) (SSL *s, WORK_STATE wst); - int (*construct_message) (SSL *s); + int (*get_construct_message_f) (SSL *s, WPACKET *pkt, + int (**confunc) (SSL *s, WPACKET *pkt), + int *mt); void (*cb) (const SSL *ssl, int type, int val) = NULL; + int (*confunc) (SSL *s, WPACKET *pkt); + int mt; + WPACKET pkt; cb = get_callback(s); @@ -703,12 +708,12 @@ static SUB_STATE_RETURN write_state_machine(SSL *s) transition = ossl_statem_server_write_transition; pre_work = ossl_statem_server_pre_work; post_work = ossl_statem_server_post_work; - construct_message = ossl_statem_server_construct_message; + get_construct_message_f = ossl_statem_server_construct_message; } else { transition = ossl_statem_client_write_transition; pre_work = ossl_statem_client_pre_work; post_work = ossl_statem_client_post_work; - construct_message = ossl_statem_client_construct_message; + get_construct_message_f = ossl_statem_client_construct_message; } while (1) { @@ -750,8 +755,16 @@ static SUB_STATE_RETURN write_state_machine(SSL *s) case WORK_FINISHED_STOP: return SUB_STATE_END_HANDSHAKE; } - if (construct_message(s) == 0) + if (!WPACKET_init(&pkt, s->init_buf) + || !get_construct_message_f(s, &pkt, &confunc, &mt) + || !ssl_set_handshake_header(s, &pkt, mt) + || (confunc != NULL && !confunc(s, &pkt)) + || !ssl_close_construct_packet(s, &pkt, mt) + || !WPACKET_finish(&pkt)) { + WPACKET_cleanup(&pkt); + ossl_statem_set_error(s); return SUB_STATE_ERROR; + } /* Fall through */