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

Side by Side Diff: net/quic/core/crypto/crypto_framer.cc

Issue 2591143003: Add QuicStrCat. (Closed)
Patch Set: sync Created 3 years, 12 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 | « net/net.gypi ('k') | net/quic/core/crypto/local_strike_register_client_test.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/quic/core/crypto/crypto_framer.h" 5 #include "net/quic/core/crypto/crypto_framer.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "net/quic/core/crypto/crypto_protocol.h" 8 #include "net/quic/core/crypto/crypto_protocol.h"
9 #include "net/quic/core/quic_data_reader.h" 9 #include "net/quic/core/quic_data_reader.h"
10 #include "net/quic/core/quic_data_writer.h" 10 #include "net/quic/core/quic_data_writer.h"
11 #include "net/quic/core/quic_packets.h" 11 #include "net/quic/core/quic_packets.h"
12 #include "net/quic/platform/api/quic_str_cat.h"
12 13
13 using base::StringPiece; 14 using base::StringPiece;
14 15
15 namespace net { 16 namespace net {
16 17
17 namespace { 18 namespace {
18 19
19 const size_t kQuicTagSize = sizeof(QuicTag); 20 const size_t kQuicTagSize = sizeof(QuicTag);
20 const size_t kCryptoEndOffsetSize = sizeof(uint32_t); 21 const size_t kCryptoEndOffsetSize = sizeof(uint32_t);
21 const size_t kNumEntriesSize = sizeof(uint16_t); 22 const size_t kNumEntriesSize = sizeof(uint16_t);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 QuicTag message_tag; 205 QuicTag message_tag;
205 reader.ReadUInt32(&message_tag); 206 reader.ReadUInt32(&message_tag);
206 message_.set_tag(message_tag); 207 message_.set_tag(message_tag);
207 state_ = STATE_READING_NUM_ENTRIES; 208 state_ = STATE_READING_NUM_ENTRIES;
208 case STATE_READING_NUM_ENTRIES: 209 case STATE_READING_NUM_ENTRIES:
209 if (reader.BytesRemaining() < kNumEntriesSize + sizeof(uint16_t)) { 210 if (reader.BytesRemaining() < kNumEntriesSize + sizeof(uint16_t)) {
210 break; 211 break;
211 } 212 }
212 reader.ReadUInt16(&num_entries_); 213 reader.ReadUInt16(&num_entries_);
213 if (num_entries_ > kMaxEntries) { 214 if (num_entries_ > kMaxEntries) {
214 error_detail_ = base::StringPrintf("%u entries", num_entries_); 215 error_detail_ = QuicStrCat(num_entries_, " entries");
215 return QUIC_CRYPTO_TOO_MANY_ENTRIES; 216 return QUIC_CRYPTO_TOO_MANY_ENTRIES;
216 } 217 }
217 uint16_t padding; 218 uint16_t padding;
218 reader.ReadUInt16(&padding); 219 reader.ReadUInt16(&padding);
219 220
220 tags_and_lengths_.reserve(num_entries_); 221 tags_and_lengths_.reserve(num_entries_);
221 state_ = STATE_READING_TAGS_AND_LENGTHS; 222 state_ = STATE_READING_TAGS_AND_LENGTHS;
222 values_len_ = 0; 223 values_len_ = 0;
223 case STATE_READING_TAGS_AND_LENGTHS: { 224 case STATE_READING_TAGS_AND_LENGTHS: {
224 if (reader.BytesRemaining() < 225 if (reader.BytesRemaining() <
225 num_entries_ * (kQuicTagSize + kCryptoEndOffsetSize)) { 226 num_entries_ * (kQuicTagSize + kCryptoEndOffsetSize)) {
226 break; 227 break;
227 } 228 }
228 229
229 uint32_t last_end_offset = 0; 230 uint32_t last_end_offset = 0;
230 for (unsigned i = 0; i < num_entries_; ++i) { 231 for (unsigned i = 0; i < num_entries_; ++i) {
231 QuicTag tag; 232 QuicTag tag;
232 reader.ReadUInt32(&tag); 233 reader.ReadUInt32(&tag);
233 if (i > 0 && tag <= tags_and_lengths_[i - 1].first) { 234 if (i > 0 && tag <= tags_and_lengths_[i - 1].first) {
234 if (tag == tags_and_lengths_[i - 1].first) { 235 if (tag == tags_and_lengths_[i - 1].first) {
235 error_detail_ = base::StringPrintf("Duplicate tag:%u", tag); 236 error_detail_ = QuicStrCat("Duplicate tag:", tag);
236 return QUIC_CRYPTO_DUPLICATE_TAG; 237 return QUIC_CRYPTO_DUPLICATE_TAG;
237 } 238 }
238 error_detail_ = base::StringPrintf("Tag %u out of order", tag); 239 error_detail_ = QuicStrCat("Tag ", tag, " out of order");
239 return QUIC_CRYPTO_TAGS_OUT_OF_ORDER; 240 return QUIC_CRYPTO_TAGS_OUT_OF_ORDER;
240 } 241 }
241 242
242 uint32_t end_offset; 243 uint32_t end_offset;
243 reader.ReadUInt32(&end_offset); 244 reader.ReadUInt32(&end_offset);
244 245
245 if (end_offset < last_end_offset) { 246 if (end_offset < last_end_offset) {
246 error_detail_ = base::StringPrintf("End offset: %u vs %u", end_offset, 247 error_detail_ =
247 last_end_offset); 248 QuicStrCat("End offset: ", end_offset, " vs ", last_end_offset);
248 return QUIC_CRYPTO_TAGS_OUT_OF_ORDER; 249 return QUIC_CRYPTO_TAGS_OUT_OF_ORDER;
249 } 250 }
250 tags_and_lengths_.push_back(std::make_pair( 251 tags_and_lengths_.push_back(std::make_pair(
251 tag, static_cast<size_t>(end_offset - last_end_offset))); 252 tag, static_cast<size_t>(end_offset - last_end_offset)));
252 last_end_offset = end_offset; 253 last_end_offset = end_offset;
253 } 254 }
254 values_len_ = last_end_offset; 255 values_len_ = last_end_offset;
255 state_ = STATE_READING_VALUES; 256 state_ = STATE_READING_VALUES;
256 } 257 }
257 case STATE_READING_VALUES: 258 case STATE_READING_VALUES:
(...skipping 25 matching lines...) Expand all
283 } 284 }
284 *end_offset += pad_length; 285 *end_offset += pad_length;
285 if (!writer->WriteUInt32(*end_offset)) { 286 if (!writer->WriteUInt32(*end_offset)) {
286 DCHECK(false) << "Failed to write end offset."; 287 DCHECK(false) << "Failed to write end offset.";
287 return false; 288 return false;
288 } 289 }
289 return true; 290 return true;
290 } 291 }
291 292
292 } // namespace net 293 } // namespace net
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | net/quic/core/crypto/local_strike_register_client_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698