Skip to content

Commit

Permalink
Don't reuse set offers/answers
Browse files Browse the repository at this point in the history
 * Setting frees an internal structure (didn't dig into which),
   resulting in a segfault from use after free. Instead, do a serialize
   / deserialize dance on these sdp objects.

 * In practice, reuse is unlikely because it should be happening in
   another process somewhere off in the interwebs. This was only
   affecting the test harness. However, it would be good to look at it a
   little harder and see whether it can be prevented even there.

 * Part of #24
  • Loading branch information
arlolra committed Feb 10, 2016
1 parent 69c86e0 commit e48abe5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions webrtc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func TestPeerConnection(t *testing.T) {
SetLoggingVerbosity(0)

Convey("PeerConnection", t, func() {
var offer *SessionDescription
var answer *SessionDescription
config := NewConfiguration(
OptionIceServer("stun:stun.l.google.com:19302, stun:another"))
So(config, ShouldNotBeNil)
Expand Down Expand Up @@ -180,7 +178,7 @@ func TestPeerConnection(t *testing.T) {
So(bob.ConnectionState(), ShouldEqual, PeerConnectionStateNew)

Convey("Alice creates offer", func() {
offer, err = alice.CreateOffer()
offer, err := alice.CreateOffer()
So(offer, ShouldNotBeNil)
So(err, ShouldBeNil)
So(alice.SignalingState(), ShouldEqual, SignalingStateStable)
Expand All @@ -193,7 +191,7 @@ func TestPeerConnection(t *testing.T) {
So(err, ShouldNotBeNil)

// Shouldn't be able to CreateAnswer
answer, err = alice.CreateAnswer()
answer, err := alice.CreateAnswer()
So(answer, ShouldBeNil)
So(err, ShouldNotBeNil)

Expand All @@ -207,9 +205,10 @@ func TestPeerConnection(t *testing.T) {
So(err, ShouldNotBeNil)

Convey("Bob receive offer and generates answer", func() {
err = bob.SetRemoteDescription(offer)
sOffer := DeserializeSessionDescription(offer.Serialize())
err = bob.SetRemoteDescription(sOffer)
So(err, ShouldBeNil)
So(bob.RemoteDescription(), ShouldEqual, offer)
So(bob.RemoteDescription(), ShouldEqual, sOffer)
So(bob.SignalingState(), ShouldEqual, SignalingStateHaveRemoteOffer)

answer, err = bob.CreateAnswer()
Expand All @@ -222,9 +221,10 @@ func TestPeerConnection(t *testing.T) {
So(bob.SignalingState(), ShouldEqual, SignalingStateStable)

Convey("Alice receives Bob's answer", func() {
err = alice.SetRemoteDescription(answer)
sAnswer := DeserializeSessionDescription(answer.Serialize())
err = alice.SetRemoteDescription(sAnswer)
So(err, ShouldBeNil)
So(alice.RemoteDescription(), ShouldEqual, answer)
So(alice.RemoteDescription(), ShouldEqual, sAnswer)
So(alice.SignalingState(), ShouldEqual, SignalingStateStable)
})
})
Expand Down

0 comments on commit e48abe5

Please sign in to comment.