Bug 1323723: added setup attribute checks. r?bwc draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Mon, 19 Dec 2016 16:01:01 -0800
changeset 451783 90c434ccedb348bb61e237e2d95dd128ac396ed9
parent 451111 d4b3146a5567a7ddbcdfa5244945db55616cb8d1
child 540133 492dd6cd3064442c0be3e56a3b57f1f061aa9505
push id39297
push userdrno@ohlmeier.org
push dateWed, 21 Dec 2016 00:39:56 +0000
reviewersbwc
bugs1323723
milestone53.0a1
Bug 1323723: added setup attribute checks. r?bwc MozReview-Commit-ID: BzlYszgySwW
media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
--- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
+++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
@@ -919,16 +919,27 @@ JsepSessionImpl::CreateAnswerMSection(co
     mSdpHelper.DisableMsection(sdp, &msection);
     return NS_OK;
   }
 
   SdpSetupAttribute::Role role;
   rv = DetermineAnswererSetupRole(remoteMsection, &role);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  if (mCurrentLocalDescription) {
+    if (mCurrentLocalDescription->GetMediaSectionCount() > mlineIndex) {
+      auto& msection = mCurrentLocalDescription->GetMediaSection(mlineIndex);
+      if (!mSdpHelper.MsectionIsDisabled(msection) &&
+          msection.GetAttributeList().GetSetup().mRole != role) {
+        JSEP_SET_ERROR("Remote side attempted to switch DTLS roles");
+        return NS_ERROR_FAILURE;
+      }
+    }
+  }
+
   rv = AddTransportAttributes(&msection, role);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = SetRecvonlySsrc(&msection);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Only attempt to match up local tracks if the offerer has elected to
   // receive traffic.
@@ -1636,21 +1647,25 @@ JsepSessionImpl::ParseSdp(const std::str
     const SdpFingerprintAttributeList& fingerprints(
         mediaAttrs.GetFingerprint());
     if (fingerprints.mFingerprints.empty()) {
       JSEP_SET_ERROR("Invalid description, no supported fingerprint algorithms "
                      "present");
       return NS_ERROR_INVALID_ARG;
     }
 
-    if (mediaAttrs.HasAttribute(SdpAttribute::kSetupAttribute) &&
-        mediaAttrs.GetSetup().mRole == SdpSetupAttribute::kHoldconn) {
-      JSEP_SET_ERROR("Description has illegal setup attribute "
-                     "\"holdconn\" at level "
-                     << i);
+    if (mediaAttrs.HasAttribute(SdpAttribute::kSetupAttribute)) {
+      if (mediaAttrs.GetSetup().mRole == SdpSetupAttribute::kHoldconn) {
+        JSEP_SET_ERROR("Description has illegal setup attribute "
+                       "\"holdconn\" at level "
+                       << i);
+        return NS_ERROR_INVALID_ARG;
+      }
+    } else {
+      JSEP_SET_ERROR("Missing setup attribute in m-line " << i);
       return NS_ERROR_INVALID_ARG;
     }
 
     auto& formats = parsed->GetMediaSection(i).GetFormats();
     for (auto f = formats.begin(); f != formats.end(); ++f) {
       uint16_t pt;
       if (!SdpHelper::GetPtAsInt(*f, &pt)) {
         JSEP_SET_ERROR("Payload type \""
@@ -1686,20 +1701,20 @@ JsepSessionImpl::ParseSdp(const std::str
       // Sanity-check that payload type can work with RTP
       for (const std::string& fmt : msection.GetFormats()) {
         uint16_t payloadType;
         // TODO (bug 1204099): Make this check for reserved ranges.
         if (!SdpHelper::GetPtAsInt(fmt, &payloadType) || payloadType > 127) {
           JSEP_SET_ERROR("audio/video payload type is too large: " << fmt);
           return NS_ERROR_INVALID_ARG;
         }
-	if (forbidden.test(payloadType)) {
-	  JSEP_SET_ERROR("Illegal audio/video payload type: " << fmt);
+        if (forbidden.test(payloadType)) {
+          JSEP_SET_ERROR("Illegal audio/video payload type: " << fmt);
           return NS_ERROR_INVALID_ARG;
-	}
+        }
       }
     }
   }
 
   *parsedp = Move(parsed);
   return NS_OK;
 }