Chromium Code Reviews| Index: remoting/host/security_key/remote_security_key_message_reader_impl.cc |
| diff --git a/remoting/host/security_key/remote_security_key_message_reader_impl.cc b/remoting/host/security_key/remote_security_key_message_reader_impl.cc |
| index 55c4061d1af7b7366f307885e3fb5ce0e04ac87f..618ebfe029988d9e7a26ccc97954af93fca5cba8 100644 |
| --- a/remoting/host/security_key/remote_security_key_message_reader_impl.cc |
| +++ b/remoting/host/security_key/remote_security_key_message_reader_impl.cc |
| @@ -85,16 +85,29 @@ void RemoteSecurityKeyMessageReaderImpl::ReadMessage() { |
| return; |
| } |
| + // Read the message type. |
| std::string message_data(total_message_size_bytes, '\0'); |
| - read_result = read_stream_.ReadAtCurrentPos(string_as_array(&message_data), |
| - total_message_size_bytes); |
| - // The static cast is safe as we know the value is smaller than max int. |
| - if (read_result != static_cast<int>(total_message_size_bytes)) { |
| - LOG(ERROR) << "Failed to read message: " << read_result; |
| + read_result = |
| + read_stream_.ReadAtCurrentPos(string_as_array(&message_data), 1); |
| + if (read_result != 1) { |
| + LOG(ERROR) << "Failed to read message type: " << read_result; |
| NotifyError(); |
| return; |
| } |
| + // Read the message payload, if one exists. |
| + if (total_message_size_bytes > 1) { |
| + uint32_t remaining_bytes = total_message_size_bytes - 1; |
| + read_result = |
| + read_stream_.ReadAtCurrentPos(&message_data[1], remaining_bytes); |
|
Sergey Ulanov
2016/04/18 18:57:32
I don't understand why you need to call ReadAtCurr
joedow
2016/04/19 17:28:10
This is a good point, my workaround isn't robust e
|
| + // The static cast is safe as we know the value is smaller than max int. |
| + if (read_result != static_cast<int>(remaining_bytes)) { |
| + LOG(ERROR) << "Failed to read message payload: " << read_result; |
| + NotifyError(); |
| + return; |
| + } |
| + } |
| + |
| std::unique_ptr<SecurityKeyMessage> message(new SecurityKeyMessage()); |
| if (!message->ParseMessage(message_data)) { |
| LOG(ERROR) << "Invalid message data received."; |