diff options
author | David Benjamin <davidben@google.com> | 2016-05-14 01:12:19 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2016-05-18 23:50:57 +0300 |
commit | a6338be3fa1a08f53d6d5f80aa4f26629fd047ab (patch) | |
tree | a954154c6b0cde257ec7b5ec20d39a3d15dbfe9b /ssl/d1_both.c | |
parent | 1f9329aaf55f9beb7c95550f5f1fffc395a5f859 (diff) |
Simplify ssl3_get_message.
Rather than this confusing coordination with the handshake state machine and
init_num changing meaning partway through, use the length field already in
BUF_MEM. Like the new record layer parsing, is no need to keep track of whether
we are reading the header or the body. Simply keep extending the handshake
message until it's far enough along.
ssl3_get_message still needs tons of work, but this allows us to disentangle it
from the handshake state.
Change-Id: Ic2b3e7cfe6152a7e28a04980317d3c7c396d9b08
Reviewed-on: https://boringssl-review.googlesource.com/7948
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'ssl/d1_both.c')
-rw-r--r-- | ssl/d1_both.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/ssl/d1_both.c b/ssl/d1_both.c index 7a624126..86fbe4a6 100644 --- a/ssl/d1_both.c +++ b/ssl/d1_both.c @@ -578,8 +578,9 @@ long dtls1_get_message(SSL *ssl, int st1, int stn, int msg_type, goto f_err; } *ok = 1; + assert(ssl->init_buf->length >= DTLS1_HM_HEADER_LENGTH); ssl->init_msg = (uint8_t *)ssl->init_buf->data + DTLS1_HM_HEADER_LENGTH; - ssl->init_num = (int)ssl->s3->tmp.message_size; + ssl->init_num = (int)ssl->init_buf->length - DTLS1_HM_HEADER_LENGTH; return ssl->init_num; } @@ -600,11 +601,10 @@ long dtls1_get_message(SSL *ssl, int st1, int stn, int msg_type, assert(frag->reassembly == NULL); /* Reconstruct the assembled message. */ - size_t len; CBB cbb; CBB_zero(&cbb); - if (!BUF_MEM_grow(ssl->init_buf, (size_t)frag->msg_header.msg_len + - DTLS1_HM_HEADER_LENGTH) || + if (!BUF_MEM_reserve(ssl->init_buf, (size_t)frag->msg_header.msg_len + + DTLS1_HM_HEADER_LENGTH) || !CBB_init_fixed(&cbb, (uint8_t *)ssl->init_buf->data, ssl->init_buf->max) || !CBB_add_u8(&cbb, frag->msg_header.type) || @@ -613,19 +613,19 @@ long dtls1_get_message(SSL *ssl, int st1, int stn, int msg_type, !CBB_add_u24(&cbb, 0 /* frag_off */) || !CBB_add_u24(&cbb, frag->msg_header.msg_len) || !CBB_add_bytes(&cbb, frag->fragment, frag->msg_header.msg_len) || - !CBB_finish(&cbb, NULL, &len)) { + !CBB_finish(&cbb, NULL, &ssl->init_buf->length)) { CBB_cleanup(&cbb); OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); goto err; } - assert(len == (size_t)frag->msg_header.msg_len + DTLS1_HM_HEADER_LENGTH); + assert(ssl->init_buf->length == + (size_t)frag->msg_header.msg_len + DTLS1_HM_HEADER_LENGTH); ssl->d1->handshake_read_seq++; /* TODO(davidben): This function has a lot of implicit outputs. Simplify the * |ssl_get_message| API. */ ssl->s3->tmp.message_type = frag->msg_header.type; - ssl->s3->tmp.message_size = frag->msg_header.msg_len; ssl->init_msg = (uint8_t *)ssl->init_buf->data + DTLS1_HM_HEADER_LENGTH; ssl->init_num = frag->msg_header.msg_len; |