webrtc::WebRtcSession is not handling correctly its state when setLocalDescription...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Jun 2017 23:06:48 +0000 (23:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Jun 2017 23:06:48 +0000 (23:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173783

Patch by Youenn Fablet <youenn@apple.com> on 2017-06-23
Reviewed by Alex Christensen.

Source/WebCore:

Test: webrtc/libwebrtc/setLocalDescriptionCrash.html

* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCMediaEndpoint::doSetLocalDescription): Fail early if there is no pending remote description and description is for an answer.

LayoutTests:

* webrtc/libwebrtc/setLocalDescriptionCrash-expected.txt: Added.
* webrtc/libwebrtc/setLocalDescriptionCrash.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218771 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webrtc/libwebrtc/setLocalDescriptionCrash-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/libwebrtc/setLocalDescriptionCrash.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

index 3291f08..0f72316 100644 (file)
@@ -1,3 +1,13 @@
+2017-06-23  Youenn Fablet  <youenn@apple.com>
+
+        webrtc::WebRtcSession is not handling correctly its state when setLocalDescription fails and is called again
+        https://bugs.webkit.org/show_bug.cgi?id=173783
+
+        Reviewed by Alex Christensen.
+
+        * webrtc/libwebrtc/setLocalDescriptionCrash-expected.txt: Added.
+        * webrtc/libwebrtc/setLocalDescriptionCrash.html: Added.
+
 2017-06-23  Matt Lewis  <jlewis3@apple.com>
 
         Added additional test expectations for webrtc/video-replace-muted-track.html.
diff --git a/LayoutTests/webrtc/libwebrtc/setLocalDescriptionCrash-expected.txt b/LayoutTests/webrtc/libwebrtc/setLocalDescriptionCrash-expected.txt
new file mode 100644 (file)
index 0000000..e41a7f8
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Testing calling twice setLocalDescription with a bad SDP 
+
diff --git a/LayoutTests/webrtc/libwebrtc/setLocalDescriptionCrash.html b/LayoutTests/webrtc/libwebrtc/setLocalDescriptionCrash.html
new file mode 100644 (file)
index 0000000..7a0142c
--- /dev/null
@@ -0,0 +1,40 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing erroneous setLocalDescription calls</title>
+        <script src="../../resources/testharness.js"></script>
+        <script src="../../resources/testharnessreport.js"></script>
+    </head>
+    <body>
+        <script>
+function badifyAnswer(answer)
+{
+    return {type: answer.type, sdp: answer.sdp.replace("BUNDLE video", "BUNDLE")};
+}
+
+promise_test((test) => {
+    var pc1 = new RTCPeerConnection;
+    var pc2 = new RTCPeerConnection;
+    var badAnswer;
+
+    pc1.addTransceiver("video");
+    return pc1.createOffer().then((offer) => {
+        return pc1.setLocalDescription(offer);
+    }).then(() => {
+        return pc2.setRemoteDescription(pc1.localDescription);
+    }).then(() => {
+        return pc2.createAnswer();
+    }).then((answer) => {
+        badAnswer = badifyAnswer(answer);
+        return pc2.setLocalDescription(badAnswer);
+    }).then(assert_unreached, (e) => {
+        assert_equals(e.message, "Failed to set local answer sdp: Failed to enable BUNDLE.");
+        return pc2.setLocalDescription(badAnswer).then(assert_unreached, (e) => {
+            assert_equals(e.message, "Failed to set local answer sdp: no pending remote description.");
+        });
+    });
+}, "Testing calling twice setLocalDescription with a bad SDP");
+        </script>
+    </body>
+</html>
index 11696e4..96bea2e 100644 (file)
@@ -1,3 +1,15 @@
+2017-06-23  Youenn Fablet  <youenn@apple.com>
+
+        webrtc::WebRtcSession is not handling correctly its state when setLocalDescription fails and is called again
+        https://bugs.webkit.org/show_bug.cgi?id=173783
+
+        Reviewed by Alex Christensen.
+
+        Test: webrtc/libwebrtc/setLocalDescriptionCrash.html
+
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::LibWebRTCMediaEndpoint::doSetLocalDescription): Fail early if there is no pending remote description and description is for an answer.
+
 2017-06-23  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream macOS] enumerateDevices should only return valid audio capture devices
index 1fc8e6d..b9f268a 100644 (file)
@@ -149,6 +149,13 @@ void LibWebRTCMediaEndpoint::doSetLocalDescription(RTCSessionDescription& descri
         m_peerConnectionBackend.setLocalDescriptionFailed(Exception { OperationError, WTFMove(errorMessage) });
         return;
     }
+
+    // FIXME: See https://bugs.webkit.org/show_bug.cgi?id=173783. Remove this test once fixed at LibWebRTC level.
+    if (description.type() == RTCSdpType::Answer && !m_backend->pending_remote_description()) {
+        m_peerConnectionBackend.setLocalDescriptionFailed(Exception { INVALID_STATE_ERR, ASCIILiteral("Failed to set local answer sdp: no pending remote description.") });
+        return;
+    }
+
     m_backend->SetLocalDescription(&m_setLocalSessionDescriptionObserver, sessionDescription.release());
 }