Use Array<uint8_t> in DTLS1_OUTGOING_MESSAGE.

The destructor is automatic but, as a bonus, it becomes size_t-clean.
Costs us 8 more bytes of per-connection memory per outgoing message,
which isn't ideal but the previous commit saved even more, and DTLS
isn't as important as TLS in that regard.

Bug: 516
Change-Id: I69f881169088a11b9f09c4dc3577c47c4b48ce60
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/54467
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
chromium-5359
David Benjamin 3 years ago committed by Boringssl LUCI CQ
parent 361e3e0aba
commit 46af243121
  1. 11
      ssl/d1_both.cc
  2. 4
      ssl/internal.h

@ -487,10 +487,7 @@ ssl_open_record_t dtls1_open_change_cipher_spec(SSL *ssl, size_t *out_consumed,
// Sending handshake messages. // Sending handshake messages.
void DTLS_OUTGOING_MESSAGE::Clear() { void DTLS_OUTGOING_MESSAGE::Clear() { data.Reset(); }
OPENSSL_free(data);
data = nullptr;
}
void dtls_clear_outgoing_messages(SSL *ssl) { void dtls_clear_outgoing_messages(SSL *ssl) {
for (size_t i = 0; i < ssl->d1->outgoing_messages_len; i++) { for (size_t i = 0; i < ssl->d1->outgoing_messages_len; i++) {
@ -578,9 +575,7 @@ static bool add_outgoing(SSL *ssl, bool is_ccs, Array<uint8_t> data) {
DTLS_OUTGOING_MESSAGE *msg = DTLS_OUTGOING_MESSAGE *msg =
&ssl->d1->outgoing_messages[ssl->d1->outgoing_messages_len]; &ssl->d1->outgoing_messages[ssl->d1->outgoing_messages_len];
size_t len; msg->data = std::move(data);
data.Release(&msg->data, &len);
msg->len = len;
msg->epoch = ssl->d1->w_epoch; msg->epoch = ssl->d1->w_epoch;
msg->is_ccs = is_ccs; msg->is_ccs = is_ccs;
@ -665,7 +660,7 @@ static enum seal_result_t seal_next_message(SSL *ssl, uint8_t *out,
// DTLS messages are serialized as a single fragment in |msg|. // DTLS messages are serialized as a single fragment in |msg|.
CBS cbs, body; CBS cbs, body;
struct hm_header_st hdr; struct hm_header_st hdr;
CBS_init(&cbs, msg->data, msg->len); CBS_init(&cbs, msg->data.data(), msg->data.size());
if (!dtls1_parse_fragment(&cbs, &hdr, &body) || if (!dtls1_parse_fragment(&cbs, &hdr, &body) ||
hdr.frag_off != 0 || hdr.frag_off != 0 ||
hdr.frag_len != CBS_len(&body) || hdr.frag_len != CBS_len(&body) ||

@ -1181,12 +1181,10 @@ struct DTLS_OUTGOING_MESSAGE {
DTLS_OUTGOING_MESSAGE() {} DTLS_OUTGOING_MESSAGE() {}
DTLS_OUTGOING_MESSAGE(const DTLS_OUTGOING_MESSAGE &) = delete; DTLS_OUTGOING_MESSAGE(const DTLS_OUTGOING_MESSAGE &) = delete;
DTLS_OUTGOING_MESSAGE &operator=(const DTLS_OUTGOING_MESSAGE &) = delete; DTLS_OUTGOING_MESSAGE &operator=(const DTLS_OUTGOING_MESSAGE &) = delete;
~DTLS_OUTGOING_MESSAGE() { Clear(); }
void Clear(); void Clear();
uint8_t *data = nullptr; Array<uint8_t> data;
uint32_t len = 0;
uint16_t epoch = 0; uint16_t epoch = 0;
bool is_ccs = false; bool is_ccs = false;
}; };

Loading…
Cancel
Save