diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 2de3075061..63d405b2b9 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -1973,6 +1973,17 @@ void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, return; } + // If a session error has occurred the PeerConnection is in a possibly + // inconsistent state so fail right away. + if (session_error() != SessionError::kNone) { + std::string error_message = GetSessionErrorMsg(); + RTC_LOG(LS_ERROR) << "CreateOffer: " << error_message; + PostCreateSessionDescriptionFailure( + observer, + RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error_message))); + return; + } + if (!ValidateOfferAnswerOptions(options)) { std::string error = "CreateOffer called with invalid options."; RTC_LOG(LS_ERROR) << error; @@ -2079,6 +2090,17 @@ void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer, return; } + // If a session error has occurred the PeerConnection is in a possibly + // inconsistent state so fail right away. + if (session_error() != SessionError::kNone) { + std::string error_message = GetSessionErrorMsg(); + RTC_LOG(LS_ERROR) << "CreateAnswer: " << error_message; + PostCreateSessionDescriptionFailure( + observer, + RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error_message))); + return; + } + if (!(signaling_state_ == kHaveRemoteOffer || signaling_state_ == kHaveLocalPrAnswer)) { std::string error = diff --git a/pc/peer_connection_crypto_unittest.cc b/pc/peer_connection_crypto_unittest.cc index cb5c0e583f..f32a124961 100644 --- a/pc/peer_connection_crypto_unittest.cc +++ b/pc/peer_connection_crypto_unittest.cc @@ -720,7 +720,8 @@ TEST_P(PeerConnectionCryptoTest, SessionErrorIfFingerprintInvalid) { ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); // Create an invalid answer with the other certificate's fingerprint. - auto invalid_answer = callee->CreateAnswer(); + auto valid_answer = callee->CreateAnswer(); + auto invalid_answer = CloneSessionDescription(valid_answer.get()); auto* audio_content = cricket::GetFirstAudioContent(invalid_answer->description()); ASSERT_TRUE(audio_content); @@ -741,7 +742,7 @@ TEST_P(PeerConnectionCryptoTest, SessionErrorIfFingerprintInvalid) { ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error)); EXPECT_PRED_FORMAT2(AssertStringContains, error, "Session error code: ERROR_CONTENT."); - ASSERT_FALSE(callee->SetLocalDescription(callee->CreateAnswer(), &error)); + ASSERT_FALSE(callee->SetLocalDescription(std::move(valid_answer), &error)); EXPECT_PRED_FORMAT2(AssertStringContains, error, "Session error code: ERROR_CONTENT."); }