| 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/spdy/spdy_frame_builder.h" | 5 #include "net/spdy/spdy_frame_builder.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/spdy/spdy_bug_tracker.h" | 10 #include "net/spdy/spdy_bug_tracker.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 uint8_t flags, | 102 uint8_t flags, |
| 103 SpdyStreamId stream_id) { | 103 SpdyStreamId stream_id) { |
| 104 DCHECK(SpdyConstants::IsValidFrameType( | 104 DCHECK(SpdyConstants::IsValidFrameType( |
| 105 version_, SpdyConstants::SerializeFrameType(version_, type))); | 105 version_, SpdyConstants::SerializeFrameType(version_, type))); |
| 106 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); | 106 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); |
| 107 DCHECK_EQ(HTTP2, framer.protocol_version()); | 107 DCHECK_EQ(HTTP2, framer.protocol_version()); |
| 108 bool success = true; | 108 bool success = true; |
| 109 if (length_ > 0) { | 109 if (length_ > 0) { |
| 110 // Update length field for previous frame. | 110 // Update length field for previous frame. |
| 111 OverwriteLength(framer, length_ - framer.GetPrefixLength(type)); | 111 OverwriteLength(framer, length_ - framer.GetPrefixLength(type)); |
| 112 SPDY_BUG_IF(SpdyConstants::GetFrameMaximumSize(version_) < length_) | 112 SPDY_BUG_IF(framer.GetFrameMaximumSize() < length_) |
| 113 << "Frame length " << length_ | 113 << "Frame length " << length_ |
| 114 << " is longer than the maximum allowed length."; | 114 << " is longer than the maximum allowed length."; |
| 115 } | 115 } |
| 116 | 116 |
| 117 offset_ += length_; | 117 offset_ += length_; |
| 118 length_ = 0; | 118 length_ = 0; |
| 119 | 119 |
| 120 // Assume all remaining capacity will be used for this frame. If not, | 120 // Assume all remaining capacity will be used for this frame. If not, |
| 121 // the length will get overwritten when we begin the next frame. | 121 // the length will get overwritten when we begin the next frame. |
| 122 // Don't check for length limits here because this may be larger than the | 122 // Don't check for length limits here because this may be larger than the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { | 165 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { |
| 166 return OverwriteLength(framer, | 166 return OverwriteLength(framer, |
| 167 length_ - framer.GetControlFrameHeaderSize()); | 167 length_ - framer.GetControlFrameHeaderSize()); |
| 168 } | 168 } |
| 169 | 169 |
| 170 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, | 170 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, |
| 171 size_t length) { | 171 size_t length) { |
| 172 if (version_ == SPDY3) { | 172 if (version_ == SPDY3) { |
| 173 DCHECK_LE(length, | 173 DCHECK_GE(framer.GetFrameMaximumSize() - framer.GetFrameMinimumSize(), |
| 174 SpdyConstants::GetFrameMaximumSize(version_) - | 174 length); |
| 175 framer.GetFrameMinimumSize()); | |
| 176 } else { | 175 } else { |
| 177 DCHECK_LE(length, SpdyConstants::GetFrameMaximumSize(version_)); | 176 DCHECK_GE(framer.GetFrameMaximumSize(), length); |
| 178 } | 177 } |
| 179 bool success = false; | 178 bool success = false; |
| 180 const size_t old_length = length_; | 179 const size_t old_length = length_; |
| 181 | 180 |
| 182 if (version_ == SPDY3) { | 181 if (version_ == SPDY3) { |
| 183 FlagsAndLength flags_length = CreateFlagsAndLength( | 182 FlagsAndLength flags_length = CreateFlagsAndLength( |
| 184 0, // We're not writing over the flags value anyway. | 183 0, // We're not writing over the flags value anyway. |
| 185 length); | 184 length); |
| 186 | 185 |
| 187 // Write into the correct location by temporarily faking the offset. | 186 // Write into the correct location by temporarily faking the offset. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 216 | 215 |
| 217 if (offset_ + length_ + length > capacity_) { | 216 if (offset_ + length_ + length > capacity_) { |
| 218 DCHECK(false); | 217 DCHECK(false); |
| 219 return false; | 218 return false; |
| 220 } | 219 } |
| 221 | 220 |
| 222 return true; | 221 return true; |
| 223 } | 222 } |
| 224 | 223 |
| 225 } // namespace net | 224 } // namespace net |
| OLD | NEW |