diff --git a/ssl/statem/statem.c b/ssl/statem/statem.c index df3008575d19604ad0f3702f7ff489d3ac0d69dd..8bc1febd1074244e64963d4e802ee1329b18dc43 100644 --- a/ssl/statem/statem.c +++ b/ssl/statem/statem.c @@ -542,6 +542,17 @@ static SUB_STATE_RETURN read_state_machine(SSL *s) return SUB_STATE_ERROR; } + /* 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)) { + ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); + SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, ERR_R_BUF_LIB); + return SUB_STATE_ERROR; + } + st->read_state = READ_STATE_BODY; /* Fall through */ diff --git a/ssl/statem/statem_lib.c b/ssl/statem/statem_lib.c index 6f13ec0daa2112c0e2ae56667538fb9b22c39468..0a482fd3a75a4dc06e76abd58304fd8e61a7095a 100644 --- a/ssl/statem/statem_lib.c +++ b/ssl/statem/statem_lib.c @@ -460,10 +460,6 @@ int tls_get_message_header(SSL *s, int *mt) */ l = RECORD_LAYER_get_rrec_length(&s->rlayer) + SSL3_HM_HEADER_LENGTH; - if (l && !BUF_MEM_grow_clean(s->init_buf, (int)l)) { - SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, ERR_R_BUF_LIB); - goto err; - } s->s3->tmp.message_size = l; s->init_msg = s->init_buf->data; @@ -476,11 +472,6 @@ int tls_get_message_header(SSL *s, int *mt) SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, SSL_R_EXCESSIVE_MESSAGE_SIZE); goto f_err; } - if (l && !BUF_MEM_grow_clean(s->init_buf, - (int)l + SSL3_HM_HEADER_LENGTH)) { - SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, ERR_R_BUF_LIB); - goto err; - } s->s3->tmp.message_size = l; s->init_msg = s->init_buf->data + SSL3_HM_HEADER_LENGTH; @@ -490,7 +481,6 @@ int tls_get_message_header(SSL *s, int *mt) return 1; f_err: ssl3_send_alert(s, SSL3_AL_FATAL, al); - err: return 0; }