Fix DCHECK crash when processing a remote answer

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 <hbos@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#40722}
This commit is contained in:
Philipp Hancke 2023-09-07 20:20:21 +02:00 committed by WebRTC LUCI CQ
parent 66b7275561
commit 5ded8ff524
2 changed files with 40 additions and 1 deletions

View File

@ -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));

View File

@ -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