LibTLS: Avoid extra initialisation of buffers that are initialised

A trace for proof:
buffer:

    L91: 0:(packet.size() - header_size)
    L98: (packet.size() - header_size):(packet.size() - header_size + mac_size)
    L102: (packet.size() - header_size + mac_size):buffer.size()
    (asserted at L103)

ct:

    L88: 0:(header_size - 2)
    L123: (header_size - 2):(header_size)
    L111: (header_size):(header_size + iv_size)
    L117: (header_size + iv_size):(header_size + iv_size + length)
    (asserted at L113)
This commit is contained in:
AnotherTest 2020-08-11 23:30:06 +04:30 committed by Andreas Kling
parent bc7a149039
commit 880b0a7600
Notes: sideshowbarker 2024-07-19 03:52:47 +09:00

View file

@ -77,12 +77,12 @@ void TLSv12::update_packet(ByteBuffer& packet)
if (m_context.crypto.created == 1) {
// `buffer' will continue to be encrypted
auto buffer = ByteBuffer::create_zeroed(length);
auto buffer = ByteBuffer::create_uninitialized(length);
size_t buffer_position = 0;
auto iv_size = iv_length();
// We need enough space for a header, iv_length bytes of IV and whatever the packet contains
auto ct = ByteBuffer::create_zeroed(length + header_size + iv_size);
auto ct = ByteBuffer::create_uninitialized(length + header_size + iv_size);
// copy the header over
ct.overwrite(0, packet.data(), header_size - 2);