Merge pull request #712 from Jiancong/master

Fix session-manager corrupted caused by memory overflow.
This commit is contained in:
Simon Fels 2018-05-17 09:27:17 +02:00 • committed by GitHub
commit 807005b2fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View file

@ -74,6 +74,7 @@ void Channel::send_message(const std::uint8_t &type,
google::protobuf::MessageLite const &message) { google::protobuf::MessageLite const &message) {
const size_t size = message.ByteSize(); const size_t size = message.ByteSize();
const unsigned char header_bytes[header_size] = { const unsigned char header_bytes[header_size] = {
static_cast<unsigned char>((size >>16) & 0xff),
static_cast<unsigned char>((size >> 8) & 0xff), static_cast<unsigned char>((size >> 8) & 0xff),
static_cast<unsigned char>((size >> 0) & 0xff), type, static_cast<unsigned char>((size >> 0) & 0xff), type,
}; };

View file

@ -20,7 +20,7 @@
namespace anbox { namespace anbox {
namespace rpc { namespace rpc {
static constexpr const long header_size{3}; static constexpr const long header_size{4};
static constexpr unsigned int const serialization_buffer_size{2048}; static constexpr unsigned int const serialization_buffer_size{2048};
enum MessageType { enum MessageType {

View file

@ -47,9 +47,10 @@ bool MessageProcessor::process_data(const std::vector<std::uint8_t> &data) {
while (buffer_.size() > 0) { while (buffer_.size() > 0) {
const auto high = buffer_[0]; const auto high = buffer_[0];
const auto low = buffer_[1]; const auto medium = buffer_[1];
size_t const message_size = (high << 8) + low; const auto low = buffer_[2];
const auto message_type = buffer_[2]; size_t const message_size = (high << 16) + (medium << 8) + low;
const auto message_type = buffer_[3];
// If we don't have yet all bytes for a new message return and wait // If we don't have yet all bytes for a new message return and wait
// until we have all. // until we have all.
@ -101,6 +102,7 @@ void MessageProcessor::send_response(::google::protobuf::uint32 id,
const size_t size = send_response_buffer.size(); const size_t size = send_response_buffer.size();
const unsigned char header_bytes[header_size] = { const unsigned char header_bytes[header_size] = {
static_cast<unsigned char>((size >> 16) & 0xff),
static_cast<unsigned char>((size >> 8) & 0xff), static_cast<unsigned char>((size >> 8) & 0xff),
static_cast<unsigned char>((size >> 0) & 0xff), MessageType::response, static_cast<unsigned char>((size >> 0) & 0xff), MessageType::response,
}; };