diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc index da34cc2935..642ff49bb9 100644 --- a/pc/peerconnection.cc +++ b/pc/peerconnection.cc @@ -6156,6 +6156,10 @@ bool PeerConnection::HasRtcpMuxEnabled(const cricket::ContentInfo* content) { static RTCError ValidateMids(const cricket::SessionDescription& description) { std::set mids; for (const cricket::ContentInfo& content : description.contents()) { + if (content.name.empty()) { + LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, + "A media section is missing a MID attribute."); + } if (!mids.insert(content.name).second) { LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "Duplicate a=mid value '" + content.name + "'."); diff --git a/pc/peerconnection_jsep_unittest.cc b/pc/peerconnection_jsep_unittest.cc index b8606646d3..7a04474787 100644 --- a/pc/peerconnection_jsep_unittest.cc +++ b/pc/peerconnection_jsep_unittest.cc @@ -1694,4 +1694,20 @@ TEST_F(PeerConnectionJsepTest, LegacyNoMidAudioVideoAnswer) { ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer))); } +// Test that SetLocalDescription fails if a=mid lines are missing. +TEST_F(PeerConnectionJsepTest, SetLocalDescriptionFailsMissingMid) { + auto caller = CreatePeerConnection(); + caller->AddAudioTrack("audio"); + + auto offer = caller->CreateOffer(); + ClearMids(offer.get()); + + std::string error; + ASSERT_FALSE(caller->SetLocalDescription(std::move(offer), &error)); + EXPECT_EQ( + "Failed to set local offer sdp: A media section is missing a MID " + "attribute.", + error); +} + } // namespace webrtc