Bug 1344556 - Part 6: Sanity check extmaps in answers. r?drno draft
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 08 Mar 2017 15:02:28 -0600
changeset 551897 e6acef51ccfb161e81c033c1df4e71cd08c754f6
parent 551896 192421c4036d3508ded0ab6deb1391635e95fc4e
child 621666 615e8b321cf71b5416910ee0f1dfef6fca53a10a
push id51186
push userbcampen@mozilla.com
push dateMon, 27 Mar 2017 16:29:37 +0000
reviewersdrno
bugs1344556
milestone55.0a1
Bug 1344556 - Part 6: Sanity check extmaps in answers. r?drno MozReview-Commit-ID: Jv91RSe9ooL
media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
--- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
+++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
@@ -2054,16 +2054,63 @@ JsepSessionImpl::ValidateAnswer(const Sd
     }
 
     if (answerAttrs.HasAttribute(SdpAttribute::kSetupAttribute, true) &&
         answerAttrs.GetSetup().mRole == SdpSetupAttribute::kActpass) {
       JSEP_SET_ERROR("Answer contains illegal setup attribute \"actpass\""
                      " at level " << i);
       return NS_ERROR_INVALID_ARG;
     }
+
+    // Sanity check extmap
+    if (answerAttrs.HasAttribute(SdpAttribute::kExtmapAttribute)) {
+      if (!offerAttrs.HasAttribute(SdpAttribute::kExtmapAttribute)) {
+        JSEP_SET_ERROR("Answer adds extmap attributes to level " << i);
+        return NS_ERROR_INVALID_ARG;
+      }
+
+      for (const auto& ansExt : answerAttrs.GetExtmap().mExtmaps) {
+        bool found = false;
+        for (const auto& offExt : offerAttrs.GetExtmap().mExtmaps) {
+          if (ansExt.extensionname == offExt.extensionname) {
+            if ((ansExt.direction | ~offExt.direction) != ansExt.direction) {
+              JSEP_SET_ERROR("Answer has inconsistent direction on extmap "
+                             "attribute at level " << i << " ("
+                             << ansExt.extensionname << "). Offer had "
+                             << offExt.direction << ", answer had "
+                             << ansExt.direction << ".");
+              return NS_ERROR_INVALID_ARG;
+            }
+
+            if (offExt.entry < 4096 && (offExt.entry != ansExt.entry)) {
+              JSEP_SET_ERROR("Answer changed id for extmap attribute at level "
+                             << i << " (" << offExt.extensionname << ") from "
+                             << offExt.entry << " to " << ansExt.entry << ".");
+              return NS_ERROR_INVALID_ARG;
+            }
+
+            if (ansExt.entry >= 4096) {
+              JSEP_SET_ERROR("Answer used an invalid id (" << ansExt.entry
+                             << ") for extmap attribute at level " << i
+                             << " (" << ansExt.extensionname << ").");
+              return NS_ERROR_INVALID_ARG;
+            }
+
+            found = true;
+            break;
+          }
+        }
+
+        if (!found) {
+          JSEP_SET_ERROR("Answer has extmap " << ansExt.extensionname << " at "
+                         "level " << i << " that was not present in offer.");
+          return NS_ERROR_INVALID_ARG;
+        }
+      }
+    }
   }
 
   return NS_OK;
 }
 
 nsresult
 JsepSessionImpl::CreateReceivingTrack(size_t mline,
                                       const Sdp& sdp,