OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 // Getting the message length from the STUN header. | 139 // Getting the message length from the STUN header. |
140 uint16_t msg_length = rtc::GetBE16(&data[2]); | 140 uint16_t msg_length = rtc::GetBE16(&data[2]); |
141 if (size != (msg_length + kStunHeaderSize)) { | 141 if (size != (msg_length + kStunHeaderSize)) { |
142 return false; | 142 return false; |
143 } | 143 } |
144 | 144 |
145 // Finding Message Integrity attribute in stun message. | 145 // Finding Message Integrity attribute in stun message. |
146 size_t current_pos = kStunHeaderSize; | 146 size_t current_pos = kStunHeaderSize; |
147 bool has_message_integrity_attr = false; | 147 bool has_message_integrity_attr = false; |
148 while (current_pos < size) { | 148 while (current_pos + 4 <= size) { |
149 uint16_t attr_type, attr_length; | 149 uint16_t attr_type, attr_length; |
150 // Getting attribute type and length. | 150 // Getting attribute type and length. |
151 attr_type = rtc::GetBE16(&data[current_pos]); | 151 attr_type = rtc::GetBE16(&data[current_pos]); |
152 attr_length = rtc::GetBE16(&data[current_pos + sizeof(attr_type)]); | 152 attr_length = rtc::GetBE16(&data[current_pos + sizeof(attr_type)]); |
153 | 153 |
154 // If M-I, sanity check it, and break out. | 154 // If M-I, sanity check it, and break out. |
155 if (attr_type == STUN_ATTR_MESSAGE_INTEGRITY) { | 155 if (attr_type == STUN_ATTR_MESSAGE_INTEGRITY) { |
156 if (attr_length != kStunMessageIntegritySize || | 156 if (attr_length != kStunMessageIntegritySize || |
157 current_pos + attr_length > size) { | 157 current_pos + sizeof(attr_type) + sizeof(attr_length) + attr_length > |
| 158 size) { |
158 return false; | 159 return false; |
159 } | 160 } |
160 has_message_integrity_attr = true; | 161 has_message_integrity_attr = true; |
161 break; | 162 break; |
162 } | 163 } |
163 | 164 |
164 // Otherwise, skip to the next attribute. | 165 // Otherwise, skip to the next attribute. |
165 current_pos += sizeof(attr_type) + sizeof(attr_length) + attr_length; | 166 current_pos += sizeof(attr_type) + sizeof(attr_length) + attr_length; |
166 if ((attr_length % 4) != 0) { | 167 if ((attr_length % 4) != 0) { |
167 current_pos += (4 - (attr_length % 4)); | 168 current_pos += (4 - (attr_length % 4)); |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 digest, sizeof(digest)); | 912 digest, sizeof(digest)); |
912 if (size == 0) { | 913 if (size == 0) { |
913 return false; | 914 return false; |
914 } | 915 } |
915 | 916 |
916 *hash = std::string(digest, size); | 917 *hash = std::string(digest, size); |
917 return true; | 918 return true; |
918 } | 919 } |
919 | 920 |
920 } // namespace cricket | 921 } // namespace cricket |
OLD | NEW |