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

Side by Side Diff: net/server/web_socket_encoder.cc

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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 | « net/server/web_socket_encoder.h ('k') | net/server/web_socket_encoder_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/server/web_socket_encoder.h" 5 #include "net/server/web_socket_encoder.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 case kOpCodeContinuation: // We don't support binary frames yet. 84 case kOpCodeContinuation: // We don't support binary frames yet.
85 case kOpCodePing: // We don't support binary frames yet. 85 case kOpCodePing: // We don't support binary frames yet.
86 case kOpCodePong: // We don't support binary frames yet. 86 case kOpCodePong: // We don't support binary frames yet.
87 default: 87 default:
88 return WebSocket::FRAME_ERROR; 88 return WebSocket::FRAME_ERROR;
89 } 89 }
90 90
91 if (client_frame && !masked) // In Hybi-17 spec client MUST mask its frame. 91 if (client_frame && !masked) // In Hybi-17 spec client MUST mask its frame.
92 return WebSocket::FRAME_ERROR; 92 return WebSocket::FRAME_ERROR;
93 93
94 uint64 payload_length64 = second_byte & kPayloadLengthMask; 94 uint64_t payload_length64 = second_byte & kPayloadLengthMask;
95 if (payload_length64 > kMaxSingleBytePayloadLength) { 95 if (payload_length64 > kMaxSingleBytePayloadLength) {
96 int extended_payload_length_size; 96 int extended_payload_length_size;
97 if (payload_length64 == kTwoBytePayloadLengthField) 97 if (payload_length64 == kTwoBytePayloadLengthField)
98 extended_payload_length_size = 2; 98 extended_payload_length_size = 2;
99 else { 99 else {
100 DCHECK(payload_length64 == kEightBytePayloadLengthField); 100 DCHECK(payload_length64 == kEightBytePayloadLengthField);
101 extended_payload_length_size = 8; 101 extended_payload_length_size = 8;
102 } 102 }
103 if (buffer_end - p < extended_payload_length_size) 103 if (buffer_end - p < extended_payload_length_size)
104 return WebSocket::FRAME_INCOMPLETE; 104 return WebSocket::FRAME_INCOMPLETE;
105 payload_length64 = 0; 105 payload_length64 = 0;
106 for (int i = 0; i < extended_payload_length_size; ++i) { 106 for (int i = 0; i < extended_payload_length_size; ++i) {
107 payload_length64 <<= 8; 107 payload_length64 <<= 8;
108 payload_length64 |= static_cast<unsigned char>(*p++); 108 payload_length64 |= static_cast<unsigned char>(*p++);
109 } 109 }
110 } 110 }
111 111
112 size_t actual_masking_key_length = masked ? kMaskingKeyWidthInBytes : 0; 112 size_t actual_masking_key_length = masked ? kMaskingKeyWidthInBytes : 0;
113 static const uint64 max_payload_length = 0x7FFFFFFFFFFFFFFFull; 113 static const uint64_t max_payload_length = 0x7FFFFFFFFFFFFFFFull;
114 static size_t max_length = std::numeric_limits<size_t>::max(); 114 static size_t max_length = std::numeric_limits<size_t>::max();
115 if (payload_length64 > max_payload_length || 115 if (payload_length64 > max_payload_length ||
116 payload_length64 + actual_masking_key_length > max_length) { 116 payload_length64 + actual_masking_key_length > max_length) {
117 // WebSocket frame length too large. 117 // WebSocket frame length too large.
118 return WebSocket::FRAME_ERROR; 118 return WebSocket::FRAME_ERROR;
119 } 119 }
120 size_t payload_length = static_cast<size_t>(payload_length64); 120 size_t payload_length = static_cast<size_t>(payload_length64);
121 121
122 size_t total_length = actual_masking_key_length + payload_length; 122 size_t total_length = actual_masking_key_length + payload_length;
123 if (static_cast<size_t>(buffer_end - p) < total_length) 123 if (static_cast<size_t>(buffer_end - p) < total_length)
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 return false; 341 return false;
342 scoped_refptr<IOBufferWithSize> buffer = 342 scoped_refptr<IOBufferWithSize> buffer =
343 deflater_->GetOutput(deflater_->CurrentOutputSize()); 343 deflater_->GetOutput(deflater_->CurrentOutputSize());
344 if (!buffer.get()) 344 if (!buffer.get())
345 return false; 345 return false;
346 *output = std::string(buffer->data(), buffer->size()); 346 *output = std::string(buffer->data(), buffer->size());
347 return true; 347 return true;
348 } 348 }
349 349
350 } // namespace net 350 } // namespace net
OLDNEW
« no previous file with comments | « net/server/web_socket_encoder.h ('k') | net/server/web_socket_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698