| OLD | NEW |
| 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" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 QuicTag message_tag; | 205 QuicTag message_tag; |
| 206 reader.ReadUInt32(&message_tag); | 206 reader.ReadUInt32(&message_tag); |
| 207 message_.set_tag(message_tag); | 207 message_.set_tag(message_tag); |
| 208 state_ = STATE_READING_NUM_ENTRIES; | 208 state_ = STATE_READING_NUM_ENTRIES; |
| 209 case STATE_READING_NUM_ENTRIES: | 209 case STATE_READING_NUM_ENTRIES: |
| 210 if (reader.BytesRemaining() < kNumEntriesSize + sizeof(uint16_t)) { | 210 if (reader.BytesRemaining() < kNumEntriesSize + sizeof(uint16_t)) { |
| 211 break; | 211 break; |
| 212 } | 212 } |
| 213 reader.ReadUInt16(&num_entries_); | 213 reader.ReadUInt16(&num_entries_); |
| 214 if (num_entries_ > kMaxEntries) { | 214 if (num_entries_ > kMaxEntries) { |
| 215 error_detail_ = base::StringPrintf("%u entries", num_entries_); | 215 error_detail_ = QuicStrCat(num_entries_, " entries"); |
| 216 return QUIC_CRYPTO_TOO_MANY_ENTRIES; | 216 return QUIC_CRYPTO_TOO_MANY_ENTRIES; |
| 217 } | 217 } |
| 218 uint16_t padding; | 218 uint16_t padding; |
| 219 reader.ReadUInt16(&padding); | 219 reader.ReadUInt16(&padding); |
| 220 | 220 |
| 221 tags_and_lengths_.reserve(num_entries_); | 221 tags_and_lengths_.reserve(num_entries_); |
| 222 state_ = STATE_READING_TAGS_AND_LENGTHS; | 222 state_ = STATE_READING_TAGS_AND_LENGTHS; |
| 223 values_len_ = 0; | 223 values_len_ = 0; |
| 224 case STATE_READING_TAGS_AND_LENGTHS: { | 224 case STATE_READING_TAGS_AND_LENGTHS: { |
| 225 if (reader.BytesRemaining() < | 225 if (reader.BytesRemaining() < |
| 226 num_entries_ * (kQuicTagSize + kCryptoEndOffsetSize)) { | 226 num_entries_ * (kQuicTagSize + kCryptoEndOffsetSize)) { |
| 227 break; | 227 break; |
| 228 } | 228 } |
| 229 | 229 |
| 230 uint32_t last_end_offset = 0; | 230 uint32_t last_end_offset = 0; |
| 231 for (unsigned i = 0; i < num_entries_; ++i) { | 231 for (unsigned i = 0; i < num_entries_; ++i) { |
| 232 QuicTag tag; | 232 QuicTag tag; |
| 233 reader.ReadUInt32(&tag); | 233 reader.ReadUInt32(&tag); |
| 234 if (i > 0 && tag <= tags_and_lengths_[i - 1].first) { | 234 if (i > 0 && tag <= tags_and_lengths_[i - 1].first) { |
| 235 if (tag == tags_and_lengths_[i - 1].first) { | 235 if (tag == tags_and_lengths_[i - 1].first) { |
| 236 error_detail_ = base::StringPrintf("Duplicate tag:%u", tag); | 236 error_detail_ = QuicStrCat("Duplicate tag:", tag); |
| 237 return QUIC_CRYPTO_DUPLICATE_TAG; | 237 return QUIC_CRYPTO_DUPLICATE_TAG; |
| 238 } | 238 } |
| 239 error_detail_ = base::StringPrintf("Tag %u out of order", tag); | 239 error_detail_ = QuicStrCat("Tag ", tag, " out of order"); |
| 240 return QUIC_CRYPTO_TAGS_OUT_OF_ORDER; | 240 return QUIC_CRYPTO_TAGS_OUT_OF_ORDER; |
| 241 } | 241 } |
| 242 | 242 |
| 243 uint32_t end_offset; | 243 uint32_t end_offset; |
| 244 reader.ReadUInt32(&end_offset); | 244 reader.ReadUInt32(&end_offset); |
| 245 | 245 |
| 246 if (end_offset < last_end_offset) { | 246 if (end_offset < last_end_offset) { |
| 247 error_detail_ = base::StringPrintf("End offset: %u vs %u", end_offset, | 247 error_detail_ = |
| 248 last_end_offset); | 248 QuicStrCat("End offset: ", end_offset, " vs ", last_end_offset); |
| 249 return QUIC_CRYPTO_TAGS_OUT_OF_ORDER; | 249 return QUIC_CRYPTO_TAGS_OUT_OF_ORDER; |
| 250 } | 250 } |
| 251 tags_and_lengths_.push_back(std::make_pair( | 251 tags_and_lengths_.push_back(std::make_pair( |
| 252 tag, static_cast<size_t>(end_offset - last_end_offset))); | 252 tag, static_cast<size_t>(end_offset - last_end_offset))); |
| 253 last_end_offset = end_offset; | 253 last_end_offset = end_offset; |
| 254 } | 254 } |
| 255 values_len_ = last_end_offset; | 255 values_len_ = last_end_offset; |
| 256 state_ = STATE_READING_VALUES; | 256 state_ = STATE_READING_VALUES; |
| 257 } | 257 } |
| 258 case STATE_READING_VALUES: | 258 case STATE_READING_VALUES: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 284 } | 284 } |
| 285 *end_offset += pad_length; | 285 *end_offset += pad_length; |
| 286 if (!writer->WriteUInt32(*end_offset)) { | 286 if (!writer->WriteUInt32(*end_offset)) { |
| 287 DCHECK(false) << "Failed to write end offset."; | 287 DCHECK(false) << "Failed to write end offset."; |
| 288 return false; | 288 return false; |
| 289 } | 289 } |
| 290 return true; | 290 return true; |
| 291 } | 291 } |
| 292 | 292 |
| 293 } // namespace net | 293 } // namespace net |
| OLD | NEW |