Remove the free_buffer parameter to release_current_message.
With on_handshake_complete, this can be managed internally by the TLS
code. The next commit will add a ton more calls to this function.
Change-Id: I91575d3e4bfcccbbe492017ae33c74b8cc1d1340
Reviewed-on: https://boringssl-review.googlesource.com/18865
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
diff --git a/ssl/s3_both.cc b/ssl/s3_both.cc
index 4d53d53..a96b910 100644
--- a/ssl/s3_both.cc
+++ b/ssl/s3_both.cc
@@ -683,6 +683,14 @@
}
int ssl3_get_message(SSL *ssl) {
+ if (ssl->s3->tmp.reuse_message) {
+ /* There must be a current message. */
+ assert(ssl->init_msg != NULL);
+ ssl->s3->tmp.reuse_message = 0;
+ } else {
+ ssl3_release_current_message(ssl);
+ }
+
/* Re-create the handshake buffer if needed. */
if (ssl->init_buf == NULL) {
ssl->init_buf = BUF_MEM_new();
@@ -700,14 +708,6 @@
ssl->s3->v2_hello_done = 1;
}
- if (ssl->s3->tmp.reuse_message) {
- /* There must be a current message. */
- assert(ssl->init_msg != NULL);
- ssl->s3->tmp.reuse_message = 0;
- } else {
- ssl3_release_current_message(ssl, 0 /* don't free buffer */);
- }
-
/* Read the message header, if we haven't yet. */
int ret = extend_handshake_buffer(ssl, SSL3_HM_HEADER_LENGTH);
if (ret <= 0) {
@@ -757,19 +757,23 @@
return hs->transcript.Update(CBS_data(&cbs), CBS_len(&cbs));
}
-void ssl3_release_current_message(SSL *ssl, int free_buffer) {
- if (ssl->init_msg != NULL) {
- /* |init_buf| never contains data beyond the current message. */
- assert(SSL3_HM_HEADER_LENGTH + ssl->init_num == ssl->init_buf->length);
-
- /* Clear the current message. */
- ssl->init_msg = NULL;
- ssl->init_num = 0;
- ssl->init_buf->length = 0;
- ssl->s3->is_v2_hello = 0;
+void ssl3_release_current_message(SSL *ssl) {
+ if (ssl->init_msg == NULL) {
+ return;
}
- if (free_buffer) {
+ /* |init_buf| never contains data beyond the current message. */
+ assert(SSL3_HM_HEADER_LENGTH + ssl->init_num == ssl->init_buf->length);
+
+ /* Clear the current message. */
+ ssl->init_msg = NULL;
+ ssl->init_num = 0;
+ ssl->init_buf->length = 0;
+ ssl->s3->is_v2_hello = 0;
+
+ /* Post-handshake messages are rare, so release the buffer after every
+ * message. During the handshake, |on_handshake_complete| will release it. */
+ if (!SSL_in_init(ssl)) {
BUF_MEM_free(ssl->init_buf);
ssl->init_buf = NULL;
}