Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: remoting/host/security_key/remote_security_key_message_reader_impl.cc

Issue 1900733002: Fixing a Dr. Memory hang in the remoting_unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the formatting for the changed files. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/host/security_key/remote_security_key_message_reader_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/security_key/remote_security_key_message_reader_impl.h" 5 #include "remoting/host/security_key/remote_security_key_message_reader_impl.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 NotifyError(); 78 NotifyError();
79 return; 79 return;
80 } 80 }
81 81
82 if (!SecurityKeyMessage::IsValidMessageSize(total_message_size_bytes)) { 82 if (!SecurityKeyMessage::IsValidMessageSize(total_message_size_bytes)) {
83 LOG(ERROR) << "Message size too large: " << total_message_size_bytes; 83 LOG(ERROR) << "Message size too large: " << total_message_size_bytes;
84 NotifyError(); 84 NotifyError();
85 return; 85 return;
86 } 86 }
87 87
88 // Read the message type.
88 std::string message_data(total_message_size_bytes, '\0'); 89 std::string message_data(total_message_size_bytes, '\0');
89 read_result = read_stream_.ReadAtCurrentPos(string_as_array(&message_data), 90 read_result =
90 total_message_size_bytes); 91 read_stream_.ReadAtCurrentPos(string_as_array(&message_data), 1);
91 // The static cast is safe as we know the value is smaller than max int. 92 if (read_result != 1) {
92 if (read_result != static_cast<int>(total_message_size_bytes)) { 93 LOG(ERROR) << "Failed to read message type: " << read_result;
93 LOG(ERROR) << "Failed to read message: " << read_result;
94 NotifyError(); 94 NotifyError();
95 return; 95 return;
96 } 96 }
97 97
98 // Read the message payload, if one exists.
99 if (total_message_size_bytes > 1) {
100 uint32_t remaining_bytes = total_message_size_bytes - 1;
101 read_result =
102 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
103 // The static cast is safe as we know the value is smaller than max int.
104 if (read_result != static_cast<int>(remaining_bytes)) {
105 LOG(ERROR) << "Failed to read message payload: " << read_result;
106 NotifyError();
107 return;
108 }
109 }
110
98 std::unique_ptr<SecurityKeyMessage> message(new SecurityKeyMessage()); 111 std::unique_ptr<SecurityKeyMessage> message(new SecurityKeyMessage());
99 if (!message->ParseMessage(message_data)) { 112 if (!message->ParseMessage(message_data)) {
100 LOG(ERROR) << "Invalid message data received."; 113 LOG(ERROR) << "Invalid message data received.";
101 NotifyError(); 114 NotifyError();
102 return; 115 return;
103 } 116 }
104 117
105 // Notify callback of the new message received. 118 // Notify callback of the new message received.
106 main_task_runner_->PostTask( 119 main_task_runner_->PostTask(
107 FROM_HERE, 120 FROM_HERE,
(...skipping 16 matching lines...) Expand all
124 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); 137 DCHECK(main_task_runner_->RunsTasksOnCurrentThread());
125 message_callback_.Run(std::move(message)); 138 message_callback_.Run(std::move(message));
126 } 139 }
127 140
128 void RemoteSecurityKeyMessageReaderImpl::InvokeErrorCallback() { 141 void RemoteSecurityKeyMessageReaderImpl::InvokeErrorCallback() {
129 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); 142 DCHECK(main_task_runner_->RunsTasksOnCurrentThread());
130 error_callback_.Run(); 143 error_callback_.Run();
131 } 144 }
132 145
133 } // namespace remoting 146 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/host/security_key/remote_security_key_message_reader_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698