From 5ded8ff5244e10ca56ced1592244aa94b6789cf7 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Thu, 7 Sep 2023 20:20:21 +0200 Subject: [PATCH] Fix DCHECK crash when processing a remote answer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit after the local offer stopped the only transceiver BUG=None Change-Id: I563207a26b6f0d8f41e5853521f05215b6a0eb09 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/319520 Reviewed-by: Henrik Boström Reviewed-by: Harald Alvestrand Commit-Queue: Philipp Hancke Cr-Commit-Position: refs/heads/main@{#40722} --- pc/jsep_transport_controller.cc | 7 ++++++- pc/sdp_offer_answer_unittest.cc | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc index 792365b521..fdf6598eea 100644 --- a/pc/jsep_transport_controller.cc +++ b/pc/jsep_transport_controller.cc @@ -641,7 +641,12 @@ RTCError JsepTransportController::ApplyDescription_n( cricket::JsepTransport* transport = GetJsepTransportForMid(content_info.name); - RTC_DCHECK(transport); + if (!transport) { + LOG_AND_RETURN_ERROR( + RTCErrorType::INVALID_PARAMETER, + "Could not find transport for m= section with mid='" + + content_info.name + "'"); + } SetIceRole_n(DetermineIceRole(transport, transport_info, type, local)); diff --git a/pc/sdp_offer_answer_unittest.cc b/pc/sdp_offer_answer_unittest.cc index 03bea2a23e..14e9557ca6 100644 --- a/pc/sdp_offer_answer_unittest.cc +++ b/pc/sdp_offer_answer_unittest.cc @@ -959,4 +959,38 @@ TEST_F(SdpOfferAnswerTest, OfferWithRtxAndNoMsidIsNotRejected) { EXPECT_TRUE(pc->SetRemoteDescription(std::move(offer))); } +TEST_F(SdpOfferAnswerTest, RejectsAnswerWithInvalidTransport) { + auto pc1 = CreatePeerConnection(); + pc1->AddAudioTrack("audio_track", {}); + auto pc2 = CreatePeerConnection(); + pc2->AddAudioTrack("anotheraudio_track", {}); + + auto initial_offer = pc1->CreateOfferAndSetAsLocal(); + ASSERT_EQ(initial_offer->description()->contents().size(), 1u); + auto mid = initial_offer->description()->contents()[0].mid(); + + EXPECT_TRUE(pc2->SetRemoteDescription(std::move(initial_offer))); + auto initial_answer = pc2->CreateAnswerAndSetAsLocal(); + + std::string sdp; + initial_answer->ToString(&sdp); + EXPECT_TRUE(pc1->SetRemoteDescription(std::move(initial_answer))); + + auto transceivers = pc1->pc()->GetTransceivers(); + ASSERT_EQ(transceivers.size(), 1u); + // This stops the only transport. + transceivers[0]->StopStandard(); + + auto subsequent_offer = pc1->CreateOfferAndSetAsLocal(); + // But the remote answers with a non-rejected m-line which is not valid. + auto bad_answer = CreateSessionDescription( + SdpType::kAnswer, + absl::StrReplaceAll(sdp, {{"a=group:BUNDLE " + mid + "\r\n", ""}})); + + RTCError error; + pc1->SetRemoteDescription(std::move(bad_answer), &error); + EXPECT_FALSE(error.ok()); + EXPECT_EQ(error.type(), RTCErrorType::INVALID_PARAMETER); +} + } // namespace webrtc