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

Side by Side Diff: google_apis/gcm/engine/connection_handler_impl.cc

Issue 600223003: [GCM] Investigatory CHECKs for crash in parsing stream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « google_apis/gcm/base/socket_stream_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "google_apis/gcm/engine/connection_handler_impl.h" 5 #include "google_apis/gcm/engine/connection_handler_impl.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "google/protobuf/io/coded_stream.h" 8 #include "google/protobuf/io/coded_stream.h"
9 #include "google_apis/gcm/base/mcs_util.h" 9 #include "google_apis/gcm/base/mcs_util.h"
10 #include "google_apis/gcm/base/socket_stream.h" 10 #include "google_apis/gcm/base/socket_stream.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 int last_error = output_stream_->last_error(); 177 int last_error = output_stream_->last_error();
178 CloseConnection(); 178 CloseConnection();
179 // If the socket stream had an error, plumb it up, else plumb up FAILED. 179 // If the socket stream had an error, plumb it up, else plumb up FAILED.
180 if (last_error == net::OK) 180 if (last_error == net::OK)
181 last_error = net::ERR_FAILED; 181 last_error = net::ERR_FAILED;
182 connection_callback_.Run(last_error); 182 connection_callback_.Run(last_error);
183 return; 183 return;
184 } 184 }
185 185
186 // Used to determine whether a Socket::Read is necessary. 186 // Used to determine whether a Socket::Read is necessary.
187 size_t min_bytes_needed = 0; 187 int min_bytes_needed = 0;
188 // Used to limit the size of the Socket::Read. 188 // Used to limit the size of the Socket::Read.
189 size_t max_bytes_needed = 0; 189 int max_bytes_needed = 0;
190 190
191 switch(state) { 191 switch(state) {
192 case MCS_VERSION_TAG_AND_SIZE: 192 case MCS_VERSION_TAG_AND_SIZE:
193 min_bytes_needed = kVersionPacketLen + kTagPacketLen + kSizePacketLenMin; 193 min_bytes_needed = kVersionPacketLen + kTagPacketLen + kSizePacketLenMin;
194 max_bytes_needed = kVersionPacketLen + kTagPacketLen + kSizePacketLenMax; 194 max_bytes_needed = kVersionPacketLen + kTagPacketLen + kSizePacketLenMax;
195 break; 195 break;
196 case MCS_TAG_AND_SIZE: 196 case MCS_TAG_AND_SIZE:
197 min_bytes_needed = kTagPacketLen + kSizePacketLenMin; 197 min_bytes_needed = kTagPacketLen + kSizePacketLenMin;
198 max_bytes_needed = kTagPacketLen + kSizePacketLenMax; 198 max_bytes_needed = kTagPacketLen + kSizePacketLenMax;
199 break; 199 break;
200 case MCS_FULL_SIZE: 200 case MCS_FULL_SIZE:
201 // If in this state, the minimum size packet length must already have been 201 // If in this state, the minimum size packet length must already have been
202 // insufficient, so set both to the max length. 202 // insufficient, so set both to the max length.
203 min_bytes_needed = kSizePacketLenMax; 203 min_bytes_needed = kSizePacketLenMax;
204 max_bytes_needed = kSizePacketLenMax; 204 max_bytes_needed = kSizePacketLenMax;
205 break; 205 break;
206 case MCS_PROTO_BYTES: 206 case MCS_PROTO_BYTES:
207 read_timeout_timer_.Reset(); 207 read_timeout_timer_.Reset();
208 // No variability in the message size, set both to the same. 208 // No variability in the message size, set both to the same.
209 min_bytes_needed = message_size_; 209 min_bytes_needed = message_size_;
210 max_bytes_needed = message_size_; 210 max_bytes_needed = message_size_;
211 break; 211 break;
212 default: 212 default:
213 NOTREACHED(); 213 NOTREACHED();
214 } 214 }
215 DCHECK_GE(max_bytes_needed, min_bytes_needed); 215 DCHECK_GE(max_bytes_needed, min_bytes_needed);
216 216
217 size_t unread_byte_count = input_stream_->UnreadByteCount(); 217 int unread_byte_count = input_stream_->UnreadByteCount();
218 if (min_bytes_needed > unread_byte_count && 218 if (min_bytes_needed > unread_byte_count &&
219 input_stream_->Refresh( 219 input_stream_->Refresh(
220 base::Bind(&ConnectionHandlerImpl::WaitForData, 220 base::Bind(&ConnectionHandlerImpl::WaitForData,
221 weak_ptr_factory_.GetWeakPtr(), 221 weak_ptr_factory_.GetWeakPtr(),
222 state), 222 state),
223 max_bytes_needed - unread_byte_count) == net::ERR_IO_PENDING) { 223 max_bytes_needed - unread_byte_count) == net::ERR_IO_PENDING) {
224 return; 224 return;
225 } 225 }
226 226
227 // Check for refresh errors. 227 // Check for refresh errors.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 socket_ = NULL; 418 socket_ = NULL;
419 handshake_complete_ = false; 419 handshake_complete_ = false;
420 message_tag_ = 0; 420 message_tag_ = 0;
421 message_size_ = 0; 421 message_size_ = 0;
422 input_stream_.reset(); 422 input_stream_.reset();
423 output_stream_.reset(); 423 output_stream_.reset();
424 weak_ptr_factory_.InvalidateWeakPtrs(); 424 weak_ptr_factory_.InvalidateWeakPtrs();
425 } 425 }
426 426
427 } // namespace gcm 427 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/base/socket_stream_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698