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

Side by Side Diff: net/websockets/websocket.cc

Issue 293055: Fix calculation of length in websocket.cc. (Closed)
Patch Set: Created 11 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 | « no previous file | 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <algorithm> 5 #include <algorithm>
6 #include <limits> 6 #include <limits>
7 7
8 #include "net/websockets/websocket.h" 8 #include "net/websockets/websocket.h"
9 9
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 while (p < end) { 373 while (p < end) {
374 unsigned char frame_byte = static_cast<unsigned char>(*p++); 374 unsigned char frame_byte = static_cast<unsigned char>(*p++);
375 if ((frame_byte & 0x80) == 0x80) { 375 if ((frame_byte & 0x80) == 0x80) {
376 int length = 0; 376 int length = 0;
377 while (p < end && (*p & 0x80) == 0x80) { 377 while (p < end && (*p & 0x80) == 0x80) {
378 if (length > std::numeric_limits<int>::max() / 128) { 378 if (length > std::numeric_limits<int>::max() / 128) {
379 // frame length overflow. 379 // frame length overflow.
380 socket_stream_->Close(); 380 socket_stream_->Close();
381 return; 381 return;
382 } 382 }
383 length = length * 128 + *p & 0x7f; 383 length = length * 128 + (*p & 0x7f);
384 ++p; 384 ++p;
385 } 385 }
386 // Checks if the frame body hasn't been completely received yet. 386 // Checks if the frame body hasn't been completely received yet.
387 // It also checks the case the frame length bytes haven't been completely 387 // It also checks the case the frame length bytes haven't been completely
388 // received yet, because p == end and length > 0 in such case. 388 // received yet, because p == end and length > 0 in such case.
389 if (p + length < end) { 389 if (p + length < end) {
390 p += length; 390 p += length;
391 next_frame = p; 391 next_frame = p;
392 } 392 }
393 } else { 393 } else {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 WebSocketDelegate* delegate = delegate_; 432 WebSocketDelegate* delegate = delegate_;
433 delegate_ = NULL; 433 delegate_ = NULL;
434 ready_state_ = CLOSED; 434 ready_state_ = CLOSED;
435 if (!socket_stream_) 435 if (!socket_stream_)
436 return; 436 return;
437 socket_stream_ = NULL; 437 socket_stream_ = NULL;
438 delegate->OnClose(this); 438 delegate->OnClose(this);
439 } 439 }
440 440
441 } // namespace net 441 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698