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

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

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

Powered by Google App Engine
This is Rietveld 408576698