Bug 1531904 - Part 3: Fix some validation logic in createDataChannel. r=jib
authorByron Campen [:bwc] <docfaraday@gmail.com>
Tue, 16 Apr 2019 16:38:32 +0000
changeset 469708 3e57d6dc64b2
parent 469707 08102fb37153
child 469709 85cc0827d8d3
push id35879
push usernerli@mozilla.com
push dateTue, 16 Apr 2019 22:01:48 +0000
treeherdermozilla-central@12a60898fdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1531904
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1531904 - Part 3: Fix some validation logic in createDataChannel. r=jib Differential Revision: https://phabricator.services.mozilla.com/D26772
dom/media/PeerConnection.jsm
netwerk/sctp/datachannel/DataChannel.cpp
--- a/dom/media/PeerConnection.jsm
+++ b/dom/media/PeerConnection.jsm
@@ -1600,35 +1600,45 @@ class RTCPeerConnection {
     return this._chain(() => new Promise((resolve, reject) => {
       this._onGetStatsSuccess = resolve;
       this._onGetStatsFailure = reject;
       this._impl.getStats(selector);
     }));
   }
 
   createDataChannel(label, {
-                      maxRetransmits, ordered, negotiated, id = 0xFFFF,
+                      maxRetransmits, ordered, negotiated, id = null,
                       maxRetransmitTime, maxPacketLifeTime,
                       protocol,
                     } = {}) {
     this._checkClosed();
     this._pcTelemetry.recordDataChannelInit(maxRetransmitTime, maxPacketLifeTime);
 
     if (maxPacketLifeTime === undefined) {
       maxPacketLifeTime = maxRetransmitTime;
     }
 
     if (maxRetransmitTime !== undefined) {
       this.logWarning("Use maxPacketLifeTime instead of deprecated maxRetransmitTime which will stop working soon in createDataChannel!");
     }
+    if (!negotiated) {
+      id = null;
+    } else if (id === null) {
+      throw new this._win.DOMException(
+          "id is required when negotiated is true", "TypeError");
+    }
     if (maxPacketLifeTime !== undefined && maxRetransmits !== undefined) {
       throw new this._win.DOMException(
           "Both maxPacketLifeTime and maxRetransmits cannot be provided",
           "InvalidParameterError");
     }
+    if (id == 65535) {
+      throw new this._win.DOMException(
+          "id cannot be 65535", "TypeError");
+    }
     // Must determine the type where we still know if entries are undefined.
     let type;
     if (maxPacketLifeTime !== undefined) {
       type = Ci.IPeerConnection.kDataChannelPartialReliableTimed;
     } else if (maxRetransmits !== undefined) {
       type = Ci.IPeerConnection.kDataChannelPartialReliableRexmit;
     } else {
       type = Ci.IPeerConnection.kDataChannelReliable;
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -2337,17 +2337,20 @@ int DataChannelConnection::ReceiveCallba
   // usrsctp defines the callback as returning an int, but doesn't use it
   return 1;
 }
 
 already_AddRefed<DataChannel> DataChannelConnection::Open(
     const nsACString &label, const nsACString &protocol, Type type,
     bool inOrder, uint32_t prValue, DataChannelListener *aListener,
     nsISupports *aContext, bool aExternalNegotiated, uint16_t aStream) {
-  // aStream == INVALID_STREAM to have the protocol allocate
+  if (!aExternalNegotiated) {
+    // aStream == INVALID_STREAM to have the protocol allocate
+    aStream = INVALID_STREAM;
+  }
   uint16_t prPolicy = SCTP_PR_SCTP_NONE;
   uint32_t flags;
 
   LOG(
       ("DC Open: label %s/%s, type %u, inorder %d, prValue %u, listener %p, "
        "context %p, external: %s, stream %u",
        PromiseFlatCString(label).get(), PromiseFlatCString(protocol).get(),
        type, inOrder, prValue, aListener, aContext,