diff options
author | Tim Oesterreich <[email protected]> | 2019-03-01 19:36:07 +0100 |
---|---|---|
committer | Hannes Rantzsch <[email protected]> | 2019-04-16 10:48:09 +0200 |
commit | bd0e4dd63fb69b86f6734cfcd24902dbcd8456ec (patch) | |
tree | 003c9bbc8b30a37e0dc379f32d87dc7ac45158e0 /src | |
parent | 59f4746a313b0ce377cffb4b6101ca5f6ebbf5cf (diff) |
properly handle iterator access
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/tls/asio/asio_stream.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h index 7ae0cbc4b..5003ffd04 100644 --- a/src/lib/tls/asio/asio_stream.h +++ b/src/lib/tls/asio/asio_stream.h @@ -396,13 +396,15 @@ class Stream : public StreamBase<Channel> // NOTE: This is not asynchronous: it encrypts the data synchronously. // Only writing on the socket is asynchronous. for(auto it = boost::asio::buffer_sequence_begin(buffers); - sent < MAX_PLAINTEXT_SIZE && it != boost::asio::buffer_sequence_end(buffers); + it != boost::asio::buffer_sequence_end(buffers); it++) { - const std::size_t to_send = - std::min<std::size_t>(MAX_PLAINTEXT_SIZE - sent, boost::asio::buffer_size(*it)); - native_handle()->send(static_cast<const uint8_t*>(it->data()), to_send); - sent += to_send; + if(sent >= MAX_PLAINTEXT_SIZE) return; + boost::asio::const_buffer buffer = *it; + const auto amount = + std::min<std::size_t>(MAX_PLAINTEXT_SIZE - sent, buffer.size()); + native_handle()->send(static_cast<const uint8_t*>(buffer.data()), amount); + sent += amount; } } catch(const std::exception&) |