Allow implementation defined STUN attributes in 0x4000-0x7FFF range

This patch modifies StunMessage to allow adding of attributes
in the 0x4000-0x7FFF range without adding them to stun.cc.

Before this patch this was allowed in the 0xC000-0xFFFF range
but the RFC specifies that both of these ranges are implementation
defined.

BUG=webrtc:8313

Change-Id: Ib74f5d02a06807aeca4fc3f1f3028271e233f004
Reviewed-on: https://webrtc-review.googlesource.com/64404
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22619}
This commit is contained in:
Jonas Oreland
2018-03-27 09:02:43 +02:00
committed by Commit Bot
parent be682d47ac
commit 16ccef7f11

View File

@ -71,15 +71,17 @@ bool StunMessage::SetTransactionID(const std::string& str) {
return true;
}
static bool ImplementationDefinedRange(int attr_type) {
return attr_type >= 0xC000 && attr_type <= 0xFFFF;
static bool DesignatedExpertRange(int attr_type) {
return
(attr_type >= 0x4000 && attr_type <= 0x7FFF) ||
(attr_type >= 0xC000 && attr_type <= 0xFFFF);
}
void StunMessage::AddAttribute(std::unique_ptr<StunAttribute> attr) {
// Fail any attributes that aren't valid for this type of message,
// but allow any type for the range that is "implementation defined"
// in the RFC.
if (!ImplementationDefinedRange(attr->type())) {
// but allow any type for the range that in the RFC is reserved for
// the "designated experts".
if (!DesignatedExpertRange(attr->type())) {
RTC_DCHECK_EQ(attr->value_type(), GetAttributeValueType(attr->type()));
}
@ -441,7 +443,7 @@ StunAttribute* StunMessage::CreateAttribute(int type, size_t length) /*const*/ {
if (value_type != STUN_VALUE_UNKNOWN) {
return StunAttribute::Create(value_type, type,
static_cast<uint16_t>(length), this);
} else if (ImplementationDefinedRange(type)) {
} else if (DesignatedExpertRange(type)) {
// Read unknown attributes as STUN_VALUE_BYTE_STRING
return StunAttribute::Create(STUN_VALUE_BYTE_STRING, type,
static_cast<uint16_t>(length), this);